Reputation: 14374
This seems to be legitimate Lua syntax:
example = { ["dummy"] = "foobar"}
Why would you use the above and not simply:
example = { dummy = "foobar"}
They appear to functionally the same...
Upvotes: 1
Views: 402
Reputation: 72422
Because field names do not have to be identifiers: they can be any string, including strings having spaces, for instance.
The second statement is valid Lua syntax and is very convenient for field names that are identifiers.
Table keys do not have to be strings: they can actually be any value (except nil) and the [expr]=expr
syntax for table entries allows the values of arbitrary expressions to be used as keys.
Upvotes: 1