lua-users home
lua-l archive

Re: Function as metatable (metafunctions?)

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


2014年03月31日 20:39 GMT+02:00 Thiago L. <fakedme@gmail.com>:
> local stringmetatable = getmetatable("")
> debug.setmetatable("", function(key)
> if key == "__metatable" then
> -- some magic
> else
> -- some other magic to get the env and do stuff (and then we use the stuff
> from the __metatable hack)
> end)
You can achieve this effect already:
local stringmetatable = getmetatable("")
debug.setmetatable("", setmetatable({},{
__index = function(key)
if key == "__metatable" then
 -- some magic
else
-- some other magic to get the env and do stuff (and then we use the stuff
from the __metatable hack)
end}))

AltStyle によって変換されたページ (->オリジナル) /