lua-users home
lua-l archive

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


>>>>> "Philippe" == Philippe Verdy <verdyp@gmail.com> writes:

 >> Well, you'd need to invent something else, because [[...]] already
 >> has a meaning in Lua. (t[[x]] is actually a function call, though
 >> not a very obvious one.)

 Philippe> I'm very curious about which function call is made, because
 Philippe> "[x]" inside "[]" cannot be a valid expression that would
 Philippe> perform some "magic" function call (which function?? with
 Philippe> which parameters?? Couldn't this magic function call be some
 Philippe> "getmetatable(object)", but with which "object "and how is
 Philippe> then used "x"?)

[[x]] is a long-bracket string literal, equivalent to "x".

So t[[x]] is equivalent to  t "x"  which is equivalent to t("x").

This isn't at all obvious - I only realized it myself when the issue
came up on the IRC channel, when someone had taken a chunk of lua code
from an autoconf file (not realizing that all the [ ] had been changed
to [[ ]] thanks to m4 syntax) and couldn't see why it gave errors about
calling something that wasn't a function.

-- 
Andrew.