[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5 global state
- From: Wim Couwenberg <w.couwenberg@...>
- Date: Thu, 14 Aug 2003 23:30:42 +0200
Hi,
> I have done some reading and I guess my question is whether
> the following scheme will work?
> /* get a C function on the stack from the global env somehow */
> <some code>
> lua_getfenv(L, ,-1);
The environment of a C function is always the _current_ C
global environment (much like in Lua 4), so your code (after
loading the chunk) could possibly be replaced by:
lua_pushvalue(L, LUA_GLOBALSINDEX);
lua_setfenv(L, -2);
> /* set the global env back to what it was b4 the lua_call */
> lua_setfenv(L, -1);
The global (C) env _never changed_ in the first place, so this
is not necessary. Remember that the lua_setfenv call only
affected the environment of the loaded chunk!
--
Wim