lua-users home
lua-l archive

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


We solved this problem in our app by providing a function to init
package.preload  Every slave state created by rings gets this run on
it and consequently has access to all of the C Lua modules embedded in
our app.  To make this more concrete, here's the code that gets run on
every state:

void luaav_install_modules(lua_State * L) {

	std::map<std::string, lua_CFunction>::iterator it;
	
	// main libs:
	for (it = mainmodules.begin(); it != mainmodules.end(); it++) {
		const char * name = it->first.c_str();
		lua_CFunction func = it->second;
		lua_pushcfunction(L, func);
		lua_pushstring(L, name);
		if (lua_pcall(L, 1, 1, 0))
			printf("loadlib error: %s", lua_tostring(L, -1));
		lua_settop(L, 0);		
	}
	lua_settop(L, 0);
	
	// opt libs:
	for (it = optmodules.begin(); it != optmodules.end(); it++) {
		const char * name = it->first.c_str();
		lua_CFunction func = it->second;
		lua_getglobal(L, "package");
		lua_getfield(L, -1, "preload");
		lua_pushcfunction(L, func);
		lua_setfield(L, -2, name);
		lua_settop(L, 0);	
	}
	lua_settop(L, 0);
	
}

On Tue, Feb 2, 2010 at 4:05 AM, Папенков Николай <papenkov@t-i-l.ru> wrote:
> Hello, list!
>
> That's the problem we are facing some time ago.
>
> Some time ago we decided to embed Kepler in Windows application to provide
> web access to it. We embedded Kepler sources (and all dependencies) as
> resources in the application. To support loading such modules from resources
> we supply new loader which replace standard loaders. That loader written in
> C because it uses WinAPI to access resources in executable.
>
> And this is where the problem arise. Slave Lua states, which created by
> Rings, do not have our loaders. That's breaks loading of needed modules for
> slave state.
>
> Is there any means to put new loader in slave state? That's not a problem if
> loader written in Lua. Is it possible to transfer 'package.loaders' table
> from master state to a slave state? Any solution or workaround?
>
> Thanks in advance, and sorry for English )
>
> P.S. It'll be very sorry if we must change from Kepler to anything else...
>