lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Aug 12, 2014, at 3:34 PM, astient@laposte.net wrote:

Sorry, i forgot to ask you why in this case Lua accept this way to define identifiers with an accent:

table={}
table["caché"]="test"

isn't this way equivalent to: table.caché="test" ? However the first one is accepted (i can do a print of table["caché"]) but the second gives an error as you explain.


Any string (and any other value as well except nil) can be used as a table key so, as you note, table[“caché”] is perfectly valid. As a convenience, Lua provides syntactic sugar when the table key is a valid identifier, allowing you to use table.foo as shorthand for table[“foo”]. However, caché is NOT a valid identifier, and so of course you cannot use the shorthand syntax for table indexing in this case. This is also true for many other strings, for example table[“12”] is valid (and quite different from table[12] of course), but table.12 is not.

—Tim