lua-users home
lua-l archive

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


One trick I use is to load up items in the preload table... It
basically makes behave the same, except when require("socket") is
called, it starts looking at preload first, so never hits filesystem
if setup right.

On 7/28/10, Tim Channon <tc@gpsl.net> wrote:
> Ah ha, that is very useful.
>
> The workaround for static I use is very simple. Delete references to
> load core from the static included .lua sources, no problem because
> statically it is already loaded.
>
> But I cannot so far build luasocket dynamic and you might have given me
> a clue on why. (I'd given up on this for the time being)
>
> On 28/07/2010 22:39, Duck wrote:
>>
>> LuaSocket annoyingly requires that the socket module be loaded first,
>> creating the socket table, into which the shared object submodule is
>> subsequently loaded. This makes it impossible (or, more accurately,
>> extremely tiresome) to link socket.core statically.
>>
>> I wish that Lua+C "combo-modules" wouldn't rely on loading the Lua code
>> first, and would build the core  code as an .so on its own.
>>
>> I simply changed luasocket.c to "luasockcore.c", like this (luasocket
>> version 2.0.2):
>>
>>
>> 92c92
>> <         luaL_openlib(L, "socket", func, 0);
>> ---
>>>         luaL_openlib(L, "socketcore", func, 0);
>> 113c113
>> < LUASOCKET_API int luaopen_socket_core(lua_State *L) {
>> ---
>>> LUASOCKET_API int luaopen_socketcore(lua_State *L) {
>>
>>
>> This allows a module called "socketcore" to be build and loaded on its
>> own, so it can be initialised at load time (statically linked).
>>
>> Then change socket.lua like this, to load socketcore.so (if not
>> statically linked) instead of looking for socket/core.so. This means
>> that socketcore.so no longer needs a pre-existing socket table.
>>
>> 13c13,22
>> < local socket = require("socket.core")
>> ---
>>>
>>> -- Because the main C package is now just 'socketcore' and not
>>> 'socket.core'
>>> -- (in order to simplify static linking), the main C entrypoint
>>> doesn't create
>>> -- a table called 'socket' with a table called 'core' inside it, but
>>> instead
>>> -- creates a single top-level table called 'socketcore'.
>>> -- So, when the call to module('socket') happens, we need to copy the
>>> -- fields and methods of 'socketcore' into the new top-level table
>>> 'socket'
>>> -- created by the module function.
>>>
>>> local socket = require("socketcore")
>> 15a25,26
>>> for k,v in base.pairs(socket) do base.socket[k] = v end
>>>
>> 42c53
>> < try = newtry()
>> ---
>>> try = socket.newtry()
>>
>> I'm hoping Diego switches to this way of loading when luasocket is
>> upgraded for Lua 5.2.
>>
>> The mime/mime.core module pair needs changing similarly. And IIRC there
>> are some Kepler modules which could do with this sort of modification too.
>>
>>
>>
>
>


-- 
Thomas Harning Jr.