lua-users home
lua-l archive

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


-- foo.lua
local function g(_ENV) print(x) end
g {print=print, x=math.sqrt(4)}
_ENV = {print=print, math=math, x=5}
print(x)

$ lua51 -v -e 'require"compat_envvar":install_searcher()' -lfoo
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
2
5

-- This is what internally gets passed to loadstring():
local _ENV = ...; return function(...) local function g(_ENV) _ENV.print(_ENV.x) end
g {print=_ENV.print, x=_ENV.math.sqrt(4)}
_ENV = {print=_ENV.print, math=_ENV.math, x=5}
_ENV.print(_ENV.x)
end

:)  This is presently implemented in [1], though might be more integrated into [2] for furthering [3].

[1] https://github.com/davidm/lua-parser-loose 
[2] https://github.com/davidm/lua-compat-env
[3] http://lua-users.org/wiki/LuaVersionCompatibility