lua-users home
lua-l archive

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


On Sat, Jan 9, 2010 at 1:29 PM, steve donovan <steve.j.donovan@gmail.com> wrote:
> debug.setfenv still works as expected in this context:

A more idiomatic Lua 5.2 way of compiling a function-with-a-context:

> in {x = 1, y = 10, loadstring = loadstring} do fn = loadstring 'return x + y' end
> = fn()
11

There's a temptation to avoid the 'loadstring=loadstring' by giving
the env a __index into _G, but then that _also_ effects the context in
which the function evaluates, which is often not what's intended.

steve d.