lua-users home
lua-l archive

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


Tom Miles wrote:
This is another, "Am I going mad" type question, I'm kind of going on
what I think might be happening.

A have several threads created with lua_newthread all running in their
own sandbox, but having access to their parents globals table (as per
all my other posts).

In some states I register a load of functions with luaL_register which
all works fine the first time they are registered, but if I destroy the
state (I must admit, I don't clear up the functions), then recreate it
and try and re-register the functions, the global table containing my
functions isn't created.  The only reason for this I can determine is
that when the functions are registered the second time, the table
already exists in packages.loaded, and seemingly this means that it
assumes the global exists as well.  Is this the case, and if so is there
an easy fix?  (At the moment I'm using lua_newtable(L); luaL_register(L,
NULL, funcs); lua_setfield(L, LUA_GLOBALSINDEX, "MyFuncs"); to make sure
that a global variable always exists, but why use 3 lines of code, when
1 should do ;) )

Tom
Have you tried setting package.loaded = nil from inside the thread?