lua-users home
lua-l archive

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


So, libraries are placed in the registry instead of the global table
of the current thread when I call "luaL_openlibs" or "register".

But, doesn't that mean the libraries are separate from the threads?
Why would only the first thread (script) I create get access to the
libraries and not the subsequent ones if all the libraries are in the
common registry?

P.S. Can someone clarify to me how much of an overhead multiple
lua_States are exactly?

On Sun, May 17, 2009 at 11:33 AM, Patrick Donnelly <batrick@batbytes.com> wrote:
> 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
>