lua-users home
lua-l archive

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


Hi Sean,

> I think what caught me up is that I haven't really played with Lua 5.2 (or Lua 5.3 until a few days ago) and I was still kind of expecting the Lua 5.1 behavior with setfenv(), which is a "local" change of a function's environment, and not the global change that happens now (because upvalues are pointers).

You can still keep it isolated if you want:

local meta
do
  local _ENV = _ENV -- localize it as needed
  meta = {
    io       = io,
    tostring = tostring,
    select   = select,
    print    = function(...)
      io.stdout:write("HERE I AM, JH ... ")
      for i = 1 , select('#',...) do
        io.stdout:write(tostring(select(i,...)),"\t")
      end
      io.stdout:write("\n")
    end
  }
end
print(debug.setupvalue(meta.print,1,meta),meta)
print(debug.getupvalue(meta.print,1))

This prints without errors under both Lua 5.2 and Lua 5.3:

_ENV    table: 0092B810
_ENV    table: 0092B810

Or is this not what you wanted in the first place?

Paul.