lua-users home
lua-l archive

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




On Jan 19, 2022 18:14, Gé Weijers <ge@weijers.org> wrote:


On Wed, Jan 19, 2022 at 7:23 AM Patrick Kurth <p.kurth@posteo.de> wrote:
[...]
local source = "rawset(_ENV, 'foo', function() print('bar') end);
foo()"

local chunk = load(source, "@a_chunk", "t", proxy)

chunk() -- prints 'bar'

env.foo() -- prints 'foo' if proxy ~= env, 'bar' if proxy == env

The original post mentioned Lua 5.1.5 so this does not work. _ENV is not a thing in Lua 5.1 if I remember correctly.

--

You are right, my mistake. I never used the old way of setting function environments, so I can't say if there is an equivalent approach. If I recall correctly, the mechanism for function environments was changed also due to issues with sandboxing like this. OP: if possible, perhaps consider to move to a more recent version of Lua.

Kind regards, patrick