Lua 5.3. What do you need to do to update code?

@Ignatz In an earlier version of Lua, table.insert could insert a value anywhere.

@Ignatz If you were refering to me, I can’t find the code that is wrong and the whole thing is way to big to post. If I knew what code is causing the error then I’m 80% of the way to a solution.

@dave1707 - why wouldn’t you do it the way I did it above? It’s simpler and less clumsy than using table.insert to add items at specific places.

table.insert(tbl,5,5) --error if table is shorter than 4
tbl[5]=5 --works regardless of length

@Ignatz from a look through the Lua source code the two methods seem to follow different code paths. tbl[5]=5 goes through the full hash-insertion mechanism for new keys. table.insert appears to set an integer key directly, somehow (unclear on exactly what it does). Perhaps this has performance implications if you are maintaining a contiguous array-like, integer key table.

Though even if it doesn’t affect performance, I’d prefer to have a mechanism which does runtime bounds checking when dealing with an array-like table. That is, if you want array semantics then you can use table.insert and the runtime enforces it — so you don’t end up with logic errors stemming from holes in your tables. It’s nice to have the option to say in your code “I’m using array semantics for this table.”

Edit: also table.insert will shift all the existing elements up in position if you insert into the middle or at the start of a table.

Edit2: From further reading of the code, I doubt there are performance differences between the two (if anything, table.insert is likely slower because it will have to bump all elements up if you don’t insert at the end).

@Simeon - it seems table.insert really is meant either for adding to the end, or inserting an item in between other items.

So if you simply want to assign something to position 5, it’s better to use tbl[5].

@Ignatz I would do it your way if that’s what I wanted to do. But I was trying to point out that in previous versions of Codea you could do a table.insert way beyond the end of the table. In Codea 2.3, you can’t.

@Simeon Stupid question, but when did Codea 2.3 become available. I’ve been on Codea 2.3 Beta for so long that I forgot that I wouldn’t see a Codea 2.3 update show in the App Store. Would it be advisable to stay on the Beta version just in case you need to make updates. Are there any differences (speed or anything else) between the real version of Codea and the Beta version.

@dave1707 2.3 available. just download from App Store to get rid of the beta dot version.

@dave1707 the release version is identical to the last beta build, however the beta builds do expire so it is advisable to update (even though it won’t be different).