lua-users home
lua-l archive

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



On Aug 12, 2014, at 10:20 AM, Sean Conner <sean@conman.org> wrote:


Read my earlier post. I don’t think the _ENV_G assignment happens when you
do a load (after all, this would have the effect of resetting _G after
every call to load()). My reading is that setting _G happens ONCE only for
the distinguished environment (when the Lua_State is initialized I
presume), and never again.

 _G is only set if you load the base library into the Lua state, either
with luaopen_base() or luaL_openlibs().  Lua itself does not use _G as far
as I can see (checked both 5.1 and 5.2), and I suspect it's there just for
convenience.

 -spc

Yep just noticed that. However this still means (as I noted), that _G is set only once (at most) when a Lua state is created. It is NOT set as part of any chunk compile/load.

—Tim