Re: Color Constant Trick
Posted: Tue Jan 22, 2013 12:11 am
I've had problems with this idea in the past where __index truncates my returned values, so I don't think this would work. It is a great idea though.
That sounds pretty strange. Do you (or anyone) have an example of code where __index causes this problem?xXxMoNkEyMaNxXx wrote:I've had problems with this idea in the past where __index truncates my returned values in the past, so I don't think this would work.
Code: Select all
local met={"lol",1,true}
function met:__index()
return unpack(self)
end
setmetatable(met,met)
print(met.asdf)
Code: Select all
"index": The indexing access table[key].
function gettable_event (table, key)
local h
if type(table) == "table" then
local v = rawget(table, key)
if v ~= nil then return v end
h = metatable(table).__index
if h == nil then return nil end
else
h = metatable(table).__index
if h == nil then
error(···)
end
end
if type(h) == "function" then
return (h(table, key)) -- call the handler
else return h[key] -- or repeat operation on it
end
end
That is awful and you are an awful person for writing it.xXxMoNkEyMaNxXx wrote:Output:Code: Select all
local met={"lol",1,true} function met:__index() return unpack(self) end setmetatable(met,met) print(met.asdf)
>lol