lua-users home
lua-l archive

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


If I understand you right, loading packages (either through require or
luaL_openlibs) places information in both the global table and the
register under the field _LOADED.  When a library is loaded, Lua
checks for its existence in the registry.  If the library is already
there, Lua only resets the registry entry and doesn't put any
information into the global table.

luaL_openlibs I'm not overly worried about.  I would just call it once
for the main state and enable the threads to access the main state's
global table through metatable editing.  The use of luaL_openlibs in
my example code was really more of an example where I didn't really
know what was going on.

Libraries loaded through "require" needs more thought, which I would
be using for any shared scripts I'd write myself.  Since these
"library scripts" may have local state, I'd want to an instance of the
library for each thread it appears in but without using the registry,
since I don't want conflicts.

So, all that's left for me to do is to figure out how to modify the
require function (from C, so I won't have to do anything on the Lua
side) so that it creates a local copy of the library in a particular
thread.