3 ms·
Does Lua have primitive arrays now? When I looked at it some years ago, it seemed to support only hash maps, and arrays were emulated using hash maps, which I f
by bxparks 3y ago
Does Lua have primitive arrays now? When I looked at it some years ago, it seemed to support only hash maps, and arrays were emulated using hash maps, which I found to be completely bizarre. There were discussions online where Lua folks were saying, no, you don't really need arrays. And I'm thinking to myself, hell yeah, I really needs arrays on resource-constrained microcontroller systems without garage collection.
- ckolkey 3y agoYeah, tables serve as both lists and maps. You can even have a table with _both_.
- debugnik 3y agoThat discussion must have been really long ago, otherwise you missed the point. Since Lua 5.0 (2003) tables are implemented as a pair of an array and a hashmap, and the array part can even handle small nil gaps. So tables used as arrays are implemented as arrays as well.
- vore 3y agoIf a table is contiguously indexed by integers from 1, the storage is optimized into an array.