3 ms·
This is one of the things expected to be fixed in 5.1.4, IIRC. # works with an array-style table (consecutive integer keys, starting from 1) and not hash-style
by silentbicycle 18y ago
This is one of the things expected to be fixed in 5.1.4, IIRC.
# works with an array-style table (consecutive integer keys, starting from 1) and not hash-style tables. Once you're familiar with Lua, you rarely confuse them -- they tend to be used very differently. Using the same variable type is mostly an efficiency trick.
I agree that counting from 1 is kind of annoying, but part of their reasoning was that Lua is targeted as a scripting language for niches that can include people who don't really program. They tried to keep "weird" programming stuff from obfuscating the tiny amount necessary for writing config or data files in Lua. It has coroutines, lexical scope, metatables, etc. when you use it for real programming, but they don't get in the way when you don't need them.
For example, from the data file for my laptop's wifi script:
device="ral0"
sudo=true
Network { key="home", nwid="barbelith", wpa="..." }
Network { key="sparrows", nwid="The Sparrows" }
Network { key="schulers", nwid="schuler-alpine" }