[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Sandboxing and thread environments
- From: William Ahern <wahern@...>
- Date: Thu, 10 Aug 2006 20:55:31 -0700
On Fri, 2006-08-11 at 13:37 +1000, D Burgess wrote:
> The following works OK /for what I am doing/
> L1 is the thread state.
>
> lua_newtable(L1); /* the env, */
> lua_createtable(L1,0,1); /* the meta table */
> lua_pushvalue(L1,LUA_GLOBALSINDEX);
> lua_setfield(L1,-2, "__index");
> lua_setmetatable(L1, -2); /* setmetatable(env, {_index = _G }) */
> lua_pushvalue(L1,-1);
> lua_replace(L1, LUA_GLOBALSINDEX);
Yes. I'm doing exactly that (well, that and also trying an alternative
approach; notice the ifdef's). Actually, you may have pasted this same
code (from whence I got mine), to a similar e-mail I posted about 8
months ago ;)
lua_pushthread(L);
lua_newtable(L);
lua_newtable(L);
lua_pushstring(L, "__index");
lua_pushvalue(L, LUA_GLOBALSINDEX);
lua_settable(L, -3);
if (1 != lua_setmetatable(L, -2))
goto luafail;
#if 0
lua_pushstring(L, "_G");
lua_pushvalue(L, -2);
lua_settable(L, -3);
#endif
#if 1
if (1 != lua_setfenv(L, -2))
goto luafail;
#else
lua_replace(L, LUA_GLOBALSINDEX);
#endif
#if 1
lua_pop(L, 1);
#endif
--
William Ahern <wahern@barracudanetworks.com>
--------------------------------------------------
This message was scanned for Spam, Spyware and Viruses
For more information, please visit:
http://www.barracudanetworks.com