Re:No Compiler – On LLVM, and writing software without a com...
by klibertp on Friday March 04, 2016 @01:24PM
(#11225743)
Here:
for var_1, ···, var_n in explist do block end
use `pairs(a_table)` to get `key, val` variables bound respectively. Use `ipairs` to get a loop over indices and values. This is very similar to Python, only with "do/end" instead of indent/dedent. What you can't do in Python, but can in Lua is to provide less variable names than the iterator function returns. For example, to get a list of keys when iterating over `(key, val)` pairs in Python you'd have to do this: for key, _ in some_dict.items()
While in Lua it's less explicit: for key in pairs(some_table)
...and that's it.
Basically making a simple foreach loop in Lua escalates everytime into a hour trial-and-error session.