lua-users home
lua-l archive

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


Maybe something like

  local newenv = {}
  local oldenv = globals()
  local oldtm = gettagmethod(tag(nil), 'getglobal)
  settagmethod(tag(nil), 'getglobal', function (varname)
    return %oldenv[varname]
  end)  -- alow new environment to use all variables from old one
  globals(newenv)   -- set new environment
  dofile(filename)
  globals(oldenv)   -- restore environment
  settagmethod(tag(nil), 'getglobal', oldtm)
  return newenv

-- Roberto