lua-users home
lua-l archive

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


From: Jerome Vuarand
> function transform(f)
>    local env = getfenv(f)
>    setfenv(f, setmetatable({callee=f}, { __index = env }))
>    return f
> end

I'll have to wrap my head around this one a bit. So, that makes the
environment for the function have a new 'global' variable be injected
between the function lookup and the 'real' global environment table?
Tricky!

> Another alternative is to use tables with a __call metamethod:

Also effective (although in one location in my particular application
function objects explicitly are expected by the runtime and tables
posing as functions don't behave quite the same way).


Thanks for the ideas!