In Lua, assigning a table with a specified key might go like this:
a = { x = 4 }
…or perhaps like…
a = { ['x'] = 4 }
Easy enough. However, if I introduce periods into the key (as in a domain name) nothing seems to work. All of the following fail:
a = { "a.b.c" = 4 }
a = { a.b.c = 4 }
a = { ['a.b.c'] = 4 }
a = { ["a.b.c"] = 4 }
a = { [a.b.c] = 4 }
All of these return the same error:
$ ./script.lua
/usr/bin/lua: ./script.lua:49: `}' expected near `='
What am I missing here? Several of the examples seem quite straight-forward and should work (while others have apparent problems).
In lua table element may be either a Name or an Expression. Citing language reference, “Names (also called identifiers) in Lua can be any string of letters, digits, and underscores, not beginning with a digit.”, and everything else is interpreted as an identifier in this context. Therefore,
a.b.cas a table index is treated as expression, which is evaluated to get the actual table index. This would work, but would be useless:Also note, that
foo.a.b.cis equal tofoo['a']['b']['c']and not tofoo['a.b.c'].