bug in building and installing luasocket

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

bug in building and installing luasocket

rober
Hello,

I have installed Lua 5.1 and I have also installed luasockets,
but I had some problems.

(1) make; make install created mime.so.x.y.z and
socket.so.x.y.z, but it did not create symbolic links
(mime.so and socket.so) to those files.
Seems like mime.so and socket.so should be created.

(2) Also it seems like libtool should/might be run by make install.

(3) Seems like user-specified options should be incorporated
via ./configure --foo instead of editing the config file itself.


Not a big deal to me, since I've already worked around
the build process. But maybe someone will consider fixing
it up so that ./configure; make; make install works.

best
Robert Dodier

Reply | Threaded
Open this post in threaded view
|

Re: bug in building and installing luasocket

Diego Nehab-3
Hi,

(1) make; make install created mime.so.x.y.z and
socket.so.x.y.z, but it did not create symbolic links
(mime.so and socket.so) to those files.
Seems like mime.so and socket.so should be created.

Not really. It should have created socket/core.so and
mime/core.so. Did this not happen?

Regards,
Diego.

Reply | Threaded
Open this post in threaded view
|

Re: bug in building and installing luasocket

Duck-2
This isn't any kind of bug :-) But I thought of it as a result of this thread.

What if LuaSocket were divided so that instead of being modulised with two shared libs in subdirectories, it consisted of two core C packages plus the various Lua components?

socket.core and mime.core are terribly useful on their own, so if they were implemented as (say) coresock and coremime, and were require()d accordingly from socket.lua and mime.lua, they could very much more easily be built and used on their own.

In particular, it would then be trivial to build a Lua binary with coresock and coremime compiled in. As it stands, you need to make (admittedly tiny) changes to both the C and Lua files to make this work. Basic socket support, at least for tcp, is close to a core feature of modern scripting...

...some say :-) I never don't link in the C cores statically. I like to avoid dependent files I know I'll always want.

Reply | Threaded
Open this post in threaded view
|

RE: bug in building and installing luasocket

Jerome Vuarand-2
Paul Ducklin wrote:
> This isn't any kind of bug :-) But I thought of it as a result of
> this thread. 
> 
> What if LuaSocket were divided so that instead of being modulised
> with two shared libs in subdirectories, it consisted of two core C
> packages plus the various Lua components?  
> 
> socket.core and mime.core are terribly useful on their own, so if
> they were implemented as (say) coresock and coremime, and were
> require()d accordingly from socket.lua and mime.lua, they could very
> much more easily be built and used on their own.   
> 
> In particular, it would then be trivial to build a Lua binary with
> coresock and coremime compiled in. As it stands, you need to make
> (admittedly tiny) changes to both the C and Lua files to make this
> work. Basic socket support, at least for tcp, is close to a core
> feature of modern scripting...    

AFAICT from the sources socket/core.so (which can also be named
socket.so) is already a submodule that is require'd from socket.lua. You
can already statically link the so file to your lua interpreter. All you
have to modify is lua.c so that it puts luaopen_socket_core C function
in package.preload Lua table. No change to either LuaSocket C code or
Lua code is necessary. You could even do the same for the Lua files,
embeddeding them in the C code, but that's slightly more work.


Reply | Threaded
Open this post in threaded view
|

Re: bug in building and installing luasocket

rober
In reply to this post by Diego Nehab-3
Quoting Diego Nehab <[hidden email]>:

> > (1) make; make install created mime.so.x.y.z and
> > socket.so.x.y.z, but it did not create symbolic links
> > (mime.so and socket.so) to those files.
> > Seems like mime.so and socket.so should be created.
>
> Not really. It should have created socket/core.so and
> mime/core.so. Did this not happen?

Yes, those files were created, and they are apparently not sufficient,
to judge by error messages from lua.

Before I go into details, let me state that I did RTFM.

I see that make install copied socket/core.so to
/usr/local/lib/lua/5.1/socket/.

When I try various assignments to LUA_CPATH, I find that
lua -l socket
fails, as shown here:

robertdodier@boulder ~]$ export LUA_CPATH='/usr/local/lib/lua/5.1'
robertdodier@boulder ~]$ lua -l socket
ua: error loading module 'socket' from file '/usr/local/lib/lua/5.1':
       /usr/local/lib/lua/5.1: cannot read file data: Is a directory
robertdodier@boulder ~]$ export LUA_CPATH='/usr/local/lib/lua/5.1/?'
robertdodier@boulder ~]$ lua -l socket
ua: error loading module 'socket' from file '/usr/local/lib/lua/5.1/socket':
       /usr/local/lib/lua/5.1/socket: cannot read file data: Is a directory
robertdodier@boulder ~]$ export LUA_CPATH='/usr/local/lib/lua/5.1/socket'
robertdodier@boulder ~]$ lua -l socket
ua: error loading module 'socket' from file '/usr/local/lib/lua/5.1/socket':
       /usr/local/lib/lua/5.1/socket: cannot read file data: Is a directory
robertdodier@boulder ~]$ export LUA_CPATH='/usr/local/lib/lua/5.1/socket/?'
robertdodier@boulder ~]$ lua -l socket
ua: module 'socket' not found:
       no field package.preload['socket']
       no file './socket.lua'
       no file '/usr/share/lua/5.1/socket.lua'
       no file '/usr/share/lua/5.1/socket/init.lua'
       no file '/usr/lib/lua/5.1/socket.lua'
       no file '/usr/lib/lua/5.1/socket/init.lua'
       no file '/usr/local/lib/lua/5.1/socket/socket'
robertdodier@boulder ~]$ export LUA_CPATH='/usr/local/lib/lua/5.1/socket/?.so'
robertdodier@boulder ~]$ lua -l socket
ua: module 'socket' not found:
       no field package.preload['socket']
       no file './socket.lua'
       no file '/usr/share/lua/5.1/socket.lua'
       no file '/usr/share/lua/5.1/socket/init.lua'
       no file '/usr/lib/lua/5.1/socket.lua'
       no file '/usr/lib/lua/5.1/socket/init.lua'
       no file '/usr/local/lib/lua/5.1/socket/socket.so'
robertdodier@boulder ~]$ export
LUA_CPATH='/usr/local/lib/lua/5.1/socket/core.so'
robertdodier@boulder ~]$ lua -l socket
ua: error loading module 'socket' from file
'/usr/local/lib/lua/5.1/socket/core.so':
       /usr/local/lib/lua/5.1/socket/core.so: undefined symbol: luaopen_socket

It seems odd that nm /usr/local/lib/lua/5.1/socket/core.so
reports that luaopen_socket_core is defined (i.e. marked by T) in core.so;
maybe that is the function that lua is looking for.
I tried other assignments (unsuccessful) to LUA_CPATH and LUA_PATH.

The only thing that works is:

cd /tmp/luasocket-2.0.1/src # i.e. cd to the build directory
export LUA_CPATH='./?.so'
lua -l socket
# now I get the lua interactive prompt

Maybe someone can explain
(1) what is supposed to appear in /usr/local/lib/lua/5.1/socket
(2) what is the appropriate setting for LUA_CPATH and/or LUA_PATH.

Thanks for any light you can shed on this problem.

Robert Dodier

Reply | Threaded
Open this post in threaded view
|

Re: bug in building and installing luasocket

Diego Nehab-3
Hi,

Maybe someone can explain
(1) what is supposed to appear in /usr/local/lib/lua/5.1/socket
(2) what is the appropriate setting for LUA_CPATH and/or LUA_PATH.

It's all explained here

    http://www.cs.princeton.edu/~diego/professional/luasocket/installation.html

You don't load core.so (socket.so) directly. It is loaded by
socket.lua. This file must be found in your LUA_PATH, not
your LUA_CPATH.

Therefore, you should have a file

    /usr/local/share/lua/5.1/socket.lua

Please make LUA_PATH point to /usr/local/share/lua/5.1,
verify the installation copied socket.lua to that directory, and try again.

[]s,
Diego.

Reply | Threaded
Open this post in threaded view
|

RE: bug in building and installing luasocket

Jerome Vuarand-2
In reply to this post by rober
[hidden email] wrote:
> [...]
> robertdodier@boulder ~]$ export
> LUA_CPATH='/usr/local/lib/lua/5.1/socket/core.so'
> robertdodier@boulder ~]$ lua -l socket
> ua: error loading module 'socket' from file
> '/usr/local/lib/lua/5.1/socket/core.so':
>        /usr/local/lib/lua/5.1/socket/core.so: undefined symbol:
> luaopen_socket 
> 
> It seems odd that nm /usr/local/lib/lua/5.1/socket/core.so
> reports that luaopen_socket_core is defined (i.e. marked by T) in
> core.so; maybe that is the function that lua is looking for. 
> I tried other assignments (unsuccessful) to LUA_CPATH and LUA_PATH.
> 
> The only thing that works is:
> 
> cd /tmp/luasocket-2.0.1/src # i.e. cd to the build directory export
> LUA_CPATH='./?.so' 
> lua -l socket
> # now I get the lua interactive prompt
> 
> Maybe someone can explain
> (1) what is supposed to appear in /usr/local/lib/lua/5.1/socket
> (2) what is the appropriate setting for LUA_CPATH and/or LUA_PATH.

Just to clarify things, socket.lua contains a Lua module, and
socket/core.so contains *ANOTHER* module. Both work together, but what
is documented on LuaSocket website is socket.lua, not socket/core.so.

Now, as you use -lsocket switch, I assume you want to load the normal
LuaSocket. In that case you have to configure LUA_PATH to point to that
socket.lua, and also, as socket.lua will require socket/core.so, you
must make LUA_CPATH point to socket/core.so.

Assuming that you have these files there:
/usr/local/share/lua/5.1/socket.lua
/usr/local/lib/lua/5.1/socket/core.so

Your LUA_PATH and LUA_CPATH should look something like :
export LUA_PATH='/usr/local/share/lua/5.1/?.lua;;'
export LUA_CPATH='/usr/local/lib/lua/5.1/?.so;;'

And if you really want to load socket.core directly as you stated in
some previous email, you must use the -lsocket.core command line switch
instead of -lsocket.


Reply | Threaded
Open this post in threaded view
|

RE: bug in building and installing luasocket

rober
Quoting Jerome Vuarand <[hidden email]>:

> Assuming that you have these files there:
> /usr/local/share/lua/5.1/socket.lua
> /usr/local/lib/lua/5.1/socket/core.so
>
> Your LUA_PATH and LUA_CPATH should look something like :
> export LUA_PATH='/usr/local/share/lua/5.1/?.lua;;'
> export LUA_CPATH='/usr/local/lib/lua/5.1/?.so;;'

Thanks, that seems to work.

Robert Dodier

Reply | Threaded
Open this post in threaded view
|

Re: bug in building and installing luasocket

Duck-2
In reply to this post by Jerome Vuarand-2
>AFAICT from the sources socket/core.so...you
>can already statically link the so file to your lua >interpreter. All you have to modify is lua.c so 
>that it puts luaopen_socket_core...in preload

What I am suggesting is a little different, viz: that the TCP/UDP core of LuaSocket be made into a package which can be require()d independently (and in advance of) the higher-protocol-level code in socket.lua and others.

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 :-)

socket/core.so could, IMO, perfectly usefully be a package in its own right. You could then load the higher-level Lua or not to suit yourself.


Reply | Threaded
Open this post in threaded view
|

RE: bug in building and installing luasocket

Jerome Vuarand-2
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.


Reply | Threaded
Open this post in threaded view
|

RE: bug in building and installing luasocket

Diego Nehab-3
Hi,

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.

Maybe the problem is that if you require socke.core, it will
create a the "socket" table, and store a variety of
functions there.  If you later require"socket" on your own,
socket.lua won't be loaded.  The "socket" table created by
sockt.core will be returned directly instead.

I think I could have set things up so that socket.core
creates its own independent module table, and then have
socket.lua explode this table into the "socket" table it
creates, adding the high-level functionality on top of that.
I didn't think it would be worth the trouble, and I am still
not sure it is.

Regards,
Diego.

Reply | Threaded
Open this post in threaded view
|

RE: bug in building and installing luasocket

Jerome Vuarand-2
Diego Nehab wrote:
>> 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. 
> 
> Maybe the problem is that if you require socke.core, it will create a
> the "socket" table, and store a variety of functions there.  If you
> later require"socket" on your own, socket.lua won't be loaded.  The
> "socket" table created by sockt.core will be returned directly
> instead.    

Unless you manually write something in package.loaded["socket"],
require("socket.core") won't, and so any call of the form
require("socket") will at least call the init function of socket module
(ie. socket.lua). That does not mean that things will be ok, but at
least the module system won't get in the way.

If the socket init function inconditionnaly overwrite the 'socket'
global table things can go wrong. If you used the 'module' function
things should be ok ('module' checks if the table exist and reuse it if
it finds one).


Reply | Threaded
Open this post in threaded view
|

RE: bug in building and installing luasocket

Diego Nehab-3
Hi,

Unless you manually write something in package.loaded["socket"],
require("socket.core") won't, and so any call of the form
require("socket") will at least call the init function of socket module
(ie. socket.lua). That does not mean that things will be ok, but at
least the module system won't get in the way.

socket.core calls luaL_openlib("socket", func, 0). Won't
this create a module table and put it in package.loaded["socket"]?

[]s,
Diego.

Reply | Threaded
Open this post in threaded view
|

RE: bug in building and installing luasocket

Jerome Vuarand-2
Diego Nehab wrote:
>> Unless you manually write something in package.loaded["socket"],
>> require("socket.core") won't, and so any call of the form
>> require("socket") will at least call the init function of socket
>> module (ie. socket.lua). That does not mean that things will be ok,
>> but at least the module system won't get in the way.
> 
> socket.core calls luaL_openlib("socket", func, 0). Won't this create
> a module table and put it in package.loaded["socket"]? 

It will, and in that case you cannot load socket after socket.core. That
should be straightforward to fix. You just have register it in
"socket.core", and at the top of socket.lua do something like:

module("socket")
local core = require("socket.core")
for k,v in pairs(core) do
    _M[k] = v
end

I think that shows it's a good habit to use the string passed to the
module init function as the module name instead of a hard coded string.
You never know how people will use (and sometime rename) your modules
(even private submodules as in that case).


Reply | Threaded
Open this post in threaded view
|

RE: bug in building and installing luasocket

Diego Nehab-3
Hi,

I think that shows it's a good habit to use the string
passed to the module init function as the module name
instead of a hard coded string.  You never know how people
will use (and sometime rename) your modules (even private
submodules as in that case).

I don't think there is anything to fix. :) There were two
options. I optimized for the common case. I did consider the
other option, but it seemed unnatural. They are the same
package, only some functionality is written in Lua.

At any rate, I am sure it is possible to load socket.core,
then hack package.loaded so that load socket.lua loads just
fine after that.  I just don't see why somebody would want
to do that, i.e., load only socket.core to save something,
then later decide he/she actually wants the whole
socket.lua thing.

Regards,
Diego.