lua-users home
lua-l archive

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


On Sat, Dec 22, 2018 at 2:54 AM Dirk Laurie <dirk.laurie@gmail.com> wrote:
Op Sa. 22 Des. 2018 om 05:48 het Jonathan Goble <jcgoble3@gmail.com> geskryf:
>
> Can a function (Lua or C) in Lua 5.2+ gain access to its caller's _ENV,

Only as an upvalue, and even then, only if your function refers to it,
e.g. via a global name.

> and if so, can it modify that table

Yes.

> and/or replace that table with a new one?

No.

Even with debug.setupvalue?
 
> What I'm looking for is an approach that allows all three (access, modify, and replace) without writing "_ENV" (or the name of any variable that refers to _ENV) anywhere in the statement that calls the function.
> Any thoughts on how to do this? Or is it not possible?

Do you grant me the debug library?

To quote the sentence immediately following one you just quoted: "I'm open to any solution, including complicated debug library hacks and/or the C API, as long as it would work consistently."