lua-users home
lua-l archive

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


Hi,

PA wrote:
> (info) link: 'gcc -bundle -undefined dynamic_lookup -o socket.so
> auxiliar.o buffer.o except.o inet.o io.o luasocket.o mime.o options.o
> select.o tcp.o timeout.o udp.o usocket.o'

Change this to: -o lsocket.so

> Even though it seems to build properly, I get "symbol `_luaopen_socket'
> not found" when trying "require( 'socket' )":

The 'require' namespace does not separate between Lua and C modules.
But LuaSocket happens to be a mixed-language library. Thus:

require("socket") is supposed to load socket.lua (Lua) which in turn does
require("lsocket") which is supposed to load lsocket.so (C).

I.e. install socket.lua into the Lua module path /usr/local/share/lua/5.1
and install lsocket.so into the C module path /usr/local/lib/lua/5.1.


I guess with require("socket") vs. require("lsocket") it's not entirely
obvious what is happening here ...

Maybe we should adopt the Python convention for naming mixed modules?
C modules get an underscore tacked in front of the module name. The Python
module has the regular module name and loads the C module in turn. I think
it sends a clear message that you are not supposed to directly load a module
whose name starts with an underscore.

In the above example we'd need to change the name of the open function
in luasocket.c (luaopen__socket), the module name (-o _socket.so) and
the require line in socket.lua (require("_socket")).

Sure, it's just a convention and module authors can do whatever they want
inside their modules. But I think it's a useful convention to follow.


The other thing I'd like to have changed is the standard for hierarchical
module names, as far as the luaopen_*() function goes. Right now LUA_OFSEP
is set to "" (the empty string). This means that

  require("project.package.module")

will search for:

  luaopen_projectpackagemodule()

Depending on the project or package name this results in difficult to
understand (or outright stupid) symbol names. I think it's much clearer
to set LUA_OFSEP to "_" (in the standard distribution!) which means
searching for:

  luaopen_project_package_module()

Opinions?

[Yes, I know I need to bribe Roberto to change this and better not hide
 it in this thread ... ;-) ]

Bye,
     Mike