lua-users home
lua-l archive

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


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
~