lua-users home
lua-l archive

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


Hello list,

I'm trying to compile Lua on an AIX machine with luasocket statically
linked in, as I don't have dlopen there... but how do I convince the
module system that the ".so"s of luasocket are already loaded, and
what is the correct sequence of "require"s? The script that I am using
is below - I'm quite sure that I'm close to the solution, but my brain
is melting.


--snip--snip--snip--

#----
#
# Lua: unpack, make the ".o"s, the ".a"s, lua, and luac
#
#----

rm -Rf ~/usrc/lua-5.0.2/
cd     ~/usrc/
gunzip <    ~/lua-5.0.2.tar.gz | tar -xvf -
cd     ~/usrc/lua-5.0.2/

cat >> config <<'%%%'
LOADLIB= -DUSE_DLOPEN=1
DLLIB= -ldl
# MYLDFLAGS= -Wl,-E
MYLDFLAGS=
EXTRA_LIBS= -lm -ldl
%%%

make CC=cc \
    CFLAGS="-I$HOME/usrc/lua-5.0.2/include/
-I$HOME/usrc/lua-5.0.2/src/ -DUSE_POPEN=1" \
  2>&1 | tee om

# A test:
bin/lua -e 'for li in io.popen("ls bin/"):lines() do print("! "..li) end' \
  2>&1 | tee ol


#----
#
# Luasocket: unpack, make luasocket.so
# (we won't use the .so, but this produces the ".o"s as a side-effect)
#
#----

rm -Rf ~/usrc/luasocket-2.0/
cd     ~/usrc/
gunzip    < ~/luasocket-2.0.tar.gz | tar -xvf -
cd     ~/usrc/luasocket-2.0/
rm        src/compat-5.1r4/*.o

LUA50DIR=$HOME/usrc/lua-5.0.2
make CC=cc CFLAGS="-I$LUA50DIR/include/ -I$LUA50DIR/src/
-I$PWD/src/compat-5.1r4/" \
     LD=cc LDFLAGS="-qmkshrobj -L$LUA50DIR/lib/ -llua -llualib" \
     SOCKET_SO=socket.so \
 2>&1 | tee om



#----
#
# Luasocket: make libluasocket.a, luasocket.c, luasocket
# (luasocket = lua + libluasocket.a)
#
#----

cd ~/usrc/luasocket-2.0/src/
ar rcu ../../lua-5.0.2/lib/libluasocket.a \
   compat-5.1r4/compat-5.1.o \
   luasocket.o timeout.o buffer.o io.o auxiliar.o options.o inet.o
tcp.o udp.o except.o select.o usocket.o \
   mime.o
ranlib ../../lua-5.0.2/lib/libluasocket.a

cd ~/usrc/lua-5.0.2/src/lua/
cp lua.c luasocket.c
patch -p0 luasocket.c <<'%%%'
68a69,75
> /* Edrx:
>  * (find-luasocket20file "src/mime.c"      "luaopen_mime_core(lua_State *L)")
>  * (find-luasocket20file "src/luasocket.c" "luaopen_socket_core(lua_State *L)")
>  */
> extern int luaopen_socket_core(lua_State *L);
> extern int luaopen_mime_core(lua_State *L);
>
77a85,87
>   /* Edrx: */
>   {"mime", luaopen_mime_core},
>   {"socket", luaopen_socket_core},
%%%
cc -I$HOME/usrc/lua-5.0.2/include/ -I$HOME/usrc/lua-5.0.2/src/ \
   -c -o luasocket.o luasocket.c
cc -o ../../bin/luasocket  luasocket.o -L../../lib -llua -llualib
-lluasocket -lm -ldl

cd $HOME/usrc/lua-5.0.2/bin/
./luasocket -e 'for k,v in socket do print(k,v) end'



#----
#
# Luasocket: install ".lua"s in ~/.lua50/
# (We don't have the ".so"s)
#
#----

rm -Rf   ~/.lua50/socket/
rm -Rf   ~/.lua50/mime/
rm -f    ~/.lua50/{compat-5.1,ltn12,socket,mime}.lua

mkdir -p ~/.lua50/
mkdir -p ~/.lua50/socket/
mkdir -p ~/.lua50/mime/
cd  ~/usrc/luasocket-2.0/
cd  ~/usrc/luasocket-2.0/src/
cp  compat-5.1r4/compat-5.1.lua               ~/.lua50/
cp  ltn12.lua socket.lua mime.lua             ~/.lua50/
cp  http.lua tp.lua ftp.lua smtp.lua url.lua  ~/.lua50/socket/

function vluasocket () {
  LUA_INIT="@$HOME/.lua50/compat-5.1.lua" \
   LUA_PATH="$HOME/.lua50/?.lua;?.lua"    \
  LUA_CPATH="$HOME/.lua50/?.dll;?.dll"    \
  ~/usrc/lua-5.0.2/bin/luasocket $*
}


--snip--snip--snip--

# The test:

function vluasocket-e () {
  LUA_INIT="@$HOME/.lua50/compat-5.1.lua" \
   LUA_PATH="$HOME/.lua50/?.lua;?.lua"    \
  LUA_CPATH="$HOME/.lua50/?.dll;?.dll"    \
  ~/usrc/lua-5.0.2/bin/luasocket -e "$1"
}

vluasocket-e '
  socket = require "socket"
  ltn12 = require "ltn12"
  url = require "socket.url"
  ftp = require "socket.ftp"
  tounix = function (str) return (string.gsub(str, "\r", "")) end
  testftp_ls = function (ftpurl)
      local t = {}
      local p = url.parse(ftpurl)
      p.command = "list"
      p.sink = ltn12.sink.table(t)
      local r, e = ftp.get(p)
      t = tounix(table.concat(t))
      t = string.gsub(t, "(\nd[^\n]*)", "%1/")  -- add slashes to dirs
      return r and t, e
    end
  print(testftp_ls("ftp://edrx:password1@aixmachine/";))
'

# Error:
# /home/edrx/usrc/lua-5.0.2/bin/luasocket:
# /home/edrx/.lua50/socket/ftp.lua:244: attempt to call field `try' (a
# nil value)

--snip--snip--snip--

  Cheers and thanks in advance,
  Edrx
    http://angg.twu.net/