[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [5.2+] Can a function access/modify/replace its caller's _ENV?
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sat, 22 Dec 2018 15:36:05 +0200
Op Sa. 22 Des. 2018 om 09:59 het Jonathan Goble <jcgoble3@gmail.com> geskryf:
>
> 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.
Does the following formulation of your question accurately convey what you ask?
~~~
function global_function()
-- ...
end
local function upvalue_function()
-- ...
end
function f1(param_function)
_ENV = {NAME='f1_env'; global_function = global_function}
global_function() -- Can this call change _ENV.NAME? Or even _ENV itself?
upvalue_function() -- Can this call change _ENV.NAME? Or even _ENV itself?
param_function() -- Can this call change _ENV.NAME? Or even _ENV itself?
end
~