[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua Lanes with package.preload and package.loader
- From: Benoit Germain <bnt.germain@...>
- Date: Wed, 16 Nov 2011 10:32:52 +0100
2011/11/16 Greg <firstname.lastname@example.org>:
>> Give a go at git HEAD and tell me how it goes.
> I think it is close.
> I tried it out and got an error:
> [string "--LANES.LUA..."]:499: function package.preload.socket.core not found in
> destination transfer database.
> To setup lua sockets, I have some code like this:
> lua_getfield(lua, LUA_GLOBALSINDEX, "package");
> lua_getfield(lua, -1, "preload");
> lua_pushcfunction(lua, luaopen_socket_core);
> lua_setfield(lua, -2, "socket.core");
> I'm expecting lanes to look for package.preload["socket.core"] not
package.preload.socket.core is just a name which is a key in a table,
it doesn't mean I have retrieved the value of
package.preload.socket.core (which doesn't exist).
I the problem is that you go through C to load some native functions.
Because of this, Lanes doesn't have knowledge of them, therefore
cannot transfer them from one Lua state to another.
Without changing Lanes, the solution is to have your C code invoked in
the target lane so that the library is registered there, and to remove
references to these functions in the lane body, by eliminating the
upvalues that reference them.
By changing Lanes, I mean I would need to offer in the Lanes generator
option a way to say I want to load dynamic libraries like what
package's all-in-one loader does.
Another option is to roll out some callback mechanism where one can
provide a 'visitor' function to the lane generator. This function
would be called from the target lane's state, receiving as argument a
function provided by the lanes internals, that the visitor should call
for each library it needs to register, passing as argument its name
and the table this library created (or something like that).