lua-users home
lua-l archive

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


> >>>>> "AD" == Alex Davies <alex.mania@iinet.net.au> writes:
>
>   AD>   local a = (1, 2, 3)[3]
>
>  it would be better to have
>
>  local a = {1, 2, 3}[3]   -- unexpected symbol near '[', why?
>
>  ps. there is weird solution: ({ 1,2,3 })[3]

This is the feature of Lua syntax. You have to enclose table
constructor (or string literal for that matter) in braces deal with it
as with general variable.

Note that this solution has performance penalty as it allocates a new table.

Alexander.