|
| 02 Jan 2016 02:26 PM |
So I want to know something. When you pass a literal table to a for loop like this:
for k, v in next, {somehugetable} do ...
Does it redeclare the table for every iteration? Is it different from doing it like this?
local a = {somehugetable} for k, v in next, a do ... |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 02 Jan 2016 02:28 PM |
| No, they're both the same but if you want to do something with the table you're going to have to use the second one. Also if the table is going to be iterated constantly (say you're doing #1 or #2 in a while loop or something) it might be a better idea to just reuse it. |
|
|
| Report Abuse |
|
|
|
| 02 Jan 2016 02:29 PM |
| So basically it becomes cached in the iterator function? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 02 Jan 2016 02:29 PM |
| Yeah. The table itself is fetched a single time and passed to the iterator function over and over. |
|
|
| Report Abuse |
|
|
|
| 02 Jan 2016 02:29 PM |
wot
When I looked up "Ninjas" in Thesaurus.com, it said "Ninja's can't be found" Well played Ninjas, well played. |
|
|
| Report Abuse |
|
|