4 ms·
You can e.g. do > stuff = { [0]="one", [1]="two" } > print(stuff[0]) one Works well; I wrote e.g. https://github.com/rochus-keller/Smalltalk#a-smalltalk
by Rochus 5y ago
You can e.g. do
> stuff = { [0]="one", [1]="two" }
> print(stuff[0])
one
Works well; I wrote e.g. https://github.com/rochus-keller/Smalltalk#a-smalltalk-80-interpreted-virtual-machine-on-luajit https://github.com/rochus-keller/Smalltalk#a-smalltalk-80-in... that way.
EDIT: even this works
> stuff = { [0]="one", "two", "three" }
> print(stuff[0]) -> one
> print(stuff[1]) -> two
- pansa2 5y ago> stuff = { [0]="one", "two", "three" } In this case, is it possible to make iteration start with the element at index 0? Maybe by implementing a custom version of `ipairs`?
- Rochus 5y agoWhen using > stuff = { [0]="one", "two", "three" } > for k,v in pairs(stuff) do print(v) end it prints all three elements in the correct order. I rarely use iterators for performance reasons anyway. Instead of ipairs one can use > for i=0,#stuff do print(stuff[i]) end