[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Sandboxing scripts, luaL_openlibs, and require
- From: Patrick Donnelly <batrick@...>
- Date: Sun, 17 May 2009 08:33:54 -0600
On Sun, May 17, 2009 at 8:26 AM, Guy Junk <guyjunkaccount@gmail.com> wrote:
> I have, and it would likely be a lot easier. I've heard that having
> more than one lua_State though takes up a lot of memory, so I'm trying
> to see if it's possible to use only one state.
It is possible. Keep in mind luaL_openlibs() uses the Lua registry to
find libraries already loaded. Because you want exclusive states, this
is not workable. One state could modify the 'math' library causing all
other independent states to reflect this change. I would avoid using
that function for anything other than the main state. You should
create a simple function that recursively copies the main state's
global environment into the new state's global environment. You should
also be careful of functions that use the registry in the Lua
libraries (particularly 'require' and the package library).
--
-Patrick Donnelly
"Let all men know thee, but no man know thee thoroughly: Men freely
ford that see the shallows."
- Benjamin Franklin