lua-users home
lua-l archive

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


> If you find a simple way around this let me know.

OK, changing the loadlib.c source so that the _LOADED table was stored
in the environment rather than the registry, then loading the loadlib
library into my thread (after setting the new thread environment) didn't
work :-(

I think the easiest way out of this in my situation is to constrain my
use of module to just the first script I run in the thread. In my design
this script has the job of setting things up for the particular game to
run. It has initialise and finalise functions that are called once by
the C framework when the thread is first created and when the thread is
finished. So I think I will have to require everything needed by that
thread in the initialise function then unrequire them in the finalise.
Ending up with something like:

function unrequire(m)
	package.loaded[m] = nil
	_G[m] = nil
end

local packages = 
{
	"a",
	"b",
	"c",
}

function _M:initialise()
	for _,v in ipairs(packages) do
		require(v)
	end
end

function _M:finalise()
	for _,v in ipairs(packages) do
		unrequire(v)
	end
end

This is not a general solution by any means, so I am still open to a
neat general solution should anyone have one.

- DC