lua-users home
lua-l archive

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


Paul Ducklin wrote:
> At the moment, if you statically link the C core and call
> luaopen_socket_core() then you end up with a loaded package called
> 'socket' containing a subset of LuaSocket. This is great, except that
> you can't then decide to load the higher level stuff because when you
> require('socket'), nothing happens because 'socket' is already loaded
> :-)     

If you call luaopen_socket_core through require, it doesn't matter much
if it was in its own dll (socket/core.so) or if it was preloaded in
package.preload. In both case it will create the module socket.core. And
nothing prevents you from loading socket (ie socket.lua) afterwards.

/* Somewhere in lua.c */
lua_getfield(L, LUA_GLOBALSINDEX, "package");
lua_getfield(L, LUA_GLOBALSINDEX, "preload");
lua_pushcfunction(L, luaopen_socket_core);
lua_setfield(L, -2, "socket.core");
lua_pop(L, 2);

And then afterwards, if you, or socket.lua requires "socket.core", it
will be taken from package.preload, and you don't need the .so, and you
don't need to modify socket.lua.