lua-users home
lua-l archive

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


If you mean that "t[[x]]" is a function call like "x(t)", then "t[[getmetatable]]" would replace "getmetatable (t)" only, it may still return nil if t has no metatable
So t[[getmetatate]].x could throw an error (indexing a key "x" in a nil object which cannot be indexed)

And so is radically different from "t[!]" that I proposed (using "!" as a new keyword along with "!keyword" or "keyword!" for other language extensions), because it is two functions calls, one for "getmetatable(t)" and conditionally replace it with a new table with "setmetatable(t, {})" if it's nil, then a conditional "__newindex(t, k)" or "__setindex(t, k)" or "__getindex(t)" for getting or setting any further key with "t[!][k]"

What I proposed also allows "t[!][!]" for metatables of metatables with the same implicit metafunction calls (getmetatable, setmetatable, _newindex, __setindex, _getindex).

get/setmetatable() and fgetenv/fsetenv are not properly integrated in the Lua language which uses some "magic" (with dependance on a "standard" library loaded in the environment) and no clear semantics.




Le dim. 24 mai 2020 à 13:30, Philippe Verdy <verdyp@gmail.com> a écrit :


Le sam. 23 mai 2020 à 15:05, Andrew Gierth <andrew@tao11.riddles.org.uk> a écrit :
>>>>> "Philippe" == Philippe Verdy <verdyp@gmail.com> writes:

 Philippe> I'm not inventing the [[...]] notation:

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.)

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