[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re: building a single lua binary with luasocket
From:       Diego Nehab <diego () tecgraf ! puc-rio ! br>
Date:       2005-05-31 12:45:33
Message-ID: Pine.LNX.4.62.0505310838090.19318 () tux
[Download RAW message or body]

Hi,

> luaopen_lsocket is a C function which needs a wrapper to be called from
> lua, as far as I am aware...

Luaopen_lsocket shouldn't be called directly from Lua. It should be
called by require, when require"lsocket" is invoked by socket.lua, which
in turn is executed when require"socket" is called by the user.

In a traditional instalation, require"lsocket" will search for
lsocket.dll and use loadlib to get luaopen_lsocket. Placing it in
package.preload["lsocket"] simply avoids the search. Everything else
works the same.

> This is not "just" placing luaopen_lsocket in package.preload["lsocket"].
> I feel that my method is more transparent in that no changes have to be
> made in lua code for it to work (after my patch is applied) and if someone
> does a require"lsocket" with the current socket then a load of "socket" will
> fail, i.e. any order of loading modules works and loading the C module first
> requires no special handling.

Why isn't this "just" placing it in package.preload? You don't need to
use lua_register. You can use lua_pushcfunction and then lua_settable 
from C.  No need to create the global "open_lsocket" or change Lua code.

Regards,
Diego.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic