[prev in list] [next in list] [prev in thread] [next in thread]
List: lua-l
Subject: Re: Problem with cross compile luasocket
From: Brian Murphy <brian () murphy ! dk>
Date: 2005-05-24 14:55:52
Message-ID: 42934078.10907 () murphy ! dk
[Download RAW message or body]
Ulrich Dziergwa wrote:
>> Ulrich Dziergwa wrote:
>>
>>
>> Hello to the list,
>>
>>
>> I try to cross compile lua and got a problem. Let me explain what
>> I have done:
>>
>> I want to use lua together with luasocket on an embedded PowerPc
>> (a PPC405). There is Linux (2.4.18) running with busybox and uClibc.
>> To make testing easier, I have a similar environment on an Intel
>> system with a cross gcc for uClibc. After crafting (and testing) some
>> lua scripts with the use of luasocket, I changed the lua makefile in
>> putting a $(CROSS) before all tools. I also change the number
>> representation to long, because the PPC405 has no FPU. Then I build a
>> new lua propper for i386 and uClibc. I tested it with the examples
>> (life, sieve ..) and it works. Now I changed the luasocket makefile
>> in the same way. Everything compiles ok. But when I try to start my
>> application, I got the following message
>>
>> ulli@asterix:/home/luatest > ./lua testapp.lua
>> ./lua: symbol 'luaL_checknumber': can't resolve symbol '@M'
>>
>>
>> .
>> . a lot more messages like this follow
>> .
>>
>>
>> ./lua: symbol 'lua_settop': can't resolve symbol '@M'
>> ./lua: compat-5.1.lua:68: Unable to resolve symbol
>> stack traceback:
>> [C]: in function `assert'
>> compat-5.1.lua:68: in function `require'
>> socket.lua:13: in function `f'
>> compat-5.1.lua:79: in function `require'
>> sipsrv.lua:237: in main chunk
>> [C]: ?
>>
>>
>> Can anybody give me a hint what the problem might be
>>
>>
>> Thanks Ulrich Dziergwa
>>
>>
>> Not really sure what the @M is a result of but in any case
>> you won't get luasocket to work like this with an integer number
>> type without work.
>> It assumes that the lua number type is double and uses
>> it to represent timeouts in seconds so 1ms becomes 0.001.
>> With an integer type all timeouts < 1s become 0 and lots of things
>> don't work.
>> It looks like a reasonably easy job to fix this and I was about to
>> start on
>> the project next week but if you get a headstart and publish your
>> results then I wouldn't be too upset ;-).
>>
>> /Brian
>
>
> Hi,
>
> sorry for my late answer, but i don't see my messages and the answer
> on the list, just found it in the archiv.
>
> Thank for the hint with number and integer, but this might be a second
> Problem.
> To rule out problems with the my buildsystem, i installed the newest
> buildroot-system for i386 from the uClibc site (this is a native
> uClibc system with compiler and binutils). After chroot in this
> system, i can build lua 5.1w6 out of the box (i don't have changed the
> number format) and run all tests. Luasocket can be build too. But both
> tother give the following error:
>
> /usr/local/bin/lua: error loading package 'socket' (Unable to resolve
> symbol)
> stack traceback:
> [C]: ?
> [C]: in function 'require'
> ./testapp.lua:239: in main chunk
> [C]: ?
>
> for me it looks like a problem with the lua require and the uClibc
> dynamic loader. As a quick fix, is there a possibility to link
> luasocket with lua like the base or string library?
>
This is almost certainly the case. Luasocket was a little difficult to
get to link
statically because it imports the lua and C functions into the same
namespace
"socket" and the new require uses the presence of the global "socket" to
signal
that the module is loaded. This means that loading the C part of
luasocket first
blocks the loading of the lua part. I patched luasocket with the
attached patch
which loads the C code into the "lsocket" namespace and then when the lua
code is "required" a socket.x is created for each lsocket.x ( and the
same for mime. )
Once the patch is applied you can add your modules to the list in lua.c
by defining
LUA_EXTRALIBS to something like
{"lsocket", luaopen_lsocket},
{"lmime", luaopen_lmime},
and then linking your statically compiled lua socket library to the lua
library.
/Brian
["name.patch" (text/x-patch)]
--- luasocket.c.orig Mon May 9 22:44:50 2005
+++ luasocket.c Mon May 9 22:45:11 2005
@@ -87,7 +87,7 @@
static int base_open(lua_State *L) {
if (sock_open()) {
/* export functions (and leave namespace table on top of stack) */
- luaL_module(L, "socket", func, 0);
+ luaL_module(L, "lsocket", func, 0);
#ifdef LUASOCKET_DEBUG
lua_pushstring(L, "DEBUG");
lua_pushboolean(L, 1);
--- mime.c.orig Tue May 10 15:51:11 2005
+++ mime.c Tue May 10 15:41:23 2005
@@ -80,7 +80,7 @@
\*-------------------------------------------------------------------------*/
MIME_API int luaopen_lmime(lua_State *L)
{
- luaL_module(L, "mime", func, 0);
+ luaL_module(L, "lmime", func, 0);
/* initialize lookup tables */
qpsetup(qpclass, qpunbase);
b64setup(b64unbase);
["namespace.patch" (text/x-patch)]
diff -ru x/lua/mime.lua luasocket-2.0-beta3/lua/mime.lua
--- lua/mime.lua Sat Jan 15 23:52:38 2005
+++ lua/mime.lua Tue May 10 16:26:44 2005
@@ -10,9 +10,17 @@
-----------------------------------------------------------------------------
local base = require("base")
local ltn12 = require("ltn12")
-local mime = require("lmime")
+require("lmime")
module("mime")
+mime.unqp = lmime.unqp
+mime.eol = lmime.eol
+mime.unb64 = lmime.unb64
+mime.wrp = lmime.wrp
+mime.dot = lmime.dot
+mime.b64 = lmime.b64
+mime.qpwrp = lmime.qpwrp
+mime.qp = lmime.qp
-- encode, decode and wrap algorithm tables
mime.encodet = {}
mime.decodet = {}
diff -ru x/lua/socket.lua luasocket-2.0-beta3/lua/socket.lua
--- lua/socket.lua Sat Jan 15 23:52:38 2005
+++ lua/socket.lua Tue May 10 16:26:53 2005
@@ -10,9 +10,19 @@
local base = require("base")
local string = require("string")
local math = require("math")
-local socket = require("lsocket")
+require("lsocket")
module("socket")
+-- Expose c functions through the socket library
+socket.protect = lsocket.protect
+socket.dns = lsocket.dns
+socket.gettime = lsocket.gettime
+socket.udp = lsocket.udp
+socket.newtry = lsocket.newtry
+socket.select = lsocket.select
+socket.tcp = lsocket.tcp
+socket.skip = lsocket.skip
+socket.sleep = lsocket.sleep
-----------------------------------------------------------------------------
-- Auxiliar functions
-----------------------------------------------------------------------------
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic