[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Returning multiple values from the __index metamethod
- From: Geoff Leyland <geoff_leyland@...>
- Date: Mon, 4 Oct 2010 18:57:10 +1300
Hi,
The LRM (p22) says the relevant pseudo-code for __index is:
...
if type(h) == "function" then
return h(table, key)
else ...
However this code:
print(setmetatable({}, { __index = function() return "one", "two" end })[1])
prints "one" with both Lua and LuaJIT.
This has been discussed before in http://lua-users.org/lists/lua-l/2007-07/msg00177.html , and it looks like the conclusion was that it's too hard to change __index to return more than one value. Since I imagine the LRM is getting edited for 5.2, any chance the pseudo-code could be updated something like this, or an explanation added?
if type(h) == "function" then
return (h(table, key))
else ...
Cheers,
Geoff