lua-users home
lua-l archive

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


Ok, now that _ENV replaces setfenv etc, how is one supposed to load a
file into a particular environment in Lua 5.2?

In Lua 5.1 it was easy (error handling etc omitted):

   local contents, err = loadfile (filename)
   local environ = {}
   -- maybe: setmetatable (environ, common_global_env)
   setfenv (contents, environ)
   contents ()

In Lua 5.2, we can't call "setfenv", so ... what do we do?

I see that the "load" function takes an "env" (4th) parameter now, but
loadfile doesn't; does this mean we can't use loadfile if we care about
the loaded file's environment?  That seems a bit annoying, as "load" in
Lua is kind of primitive, and can't just be used easily with files like
loadfile can...

Also, what about from C?  lua_load there _doesn't_ take an env
parameter, so what should we do then...?

Thanks,

-Miles

-- 
=====
(^o^;
(()))
*This is the cute octopus virus, please copy it into your sig so it can spread.