Quick
index
main
eev
eepitch
maths
angg
blogme
dednat6
littlelangs
PURO
(C2,C3,C4,
 λ,ES,
 GA,MD,
 Caepro,
 textos,
 Chapa 1)

emacs
lua
(la)tex
maxima
git
lean4
agda
forth
squeak
icon
tcl
tikz
fvwm
debian
irc
contact

LuaSocket

Its main page: http://www.cs.princeton.edu/~diego/professional/luasocket/.

QUick index:


Compiling Lua with LuaSocket statically linked in on AIX

E-mails on the mailing list: on 2005-12, msgs 313, 314, 320.

The executable version of the e-script below lives here.

Ingredients: bash, ~/lua-5.0.2.tar.gz, ~/luasocket-2.0.tar.gz.

#----
#
# 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 LD=cc \
  CFLAGS="-I$LUA50DIR/include/ -I$LUA50DIR/src/ -I$PWD/src/compat-5.1r4/" \
  LDFLAGS="-qmkshrobj -L$LUA50DIR/lib/ -llua -llualib" \
  SOCKET_SO=socket.so \
  2>&1 | tee om

#----
#
# Luasocket: make 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

#----
#
# Lua: make preload_socket.c, luasocket.o, luasocket
# (luasocket = lua + libluasocket.a)
#
#----

cd ~/usrc/lua-5.0.2/src/lua/

cat > preload_socket.c <<'%%%'
extern int luaopen_socket_core(lua_State *L);
extern int luaopen_mime_core(lua_State *L);
/*
 * written by prec from #lua@freenode
 */
LUALIB_API int preload_socket (lua_State *L) {
  lua_pushliteral(L, "package");             /* "package" */
  lua_newtable(L);                           /* "package" T1 */
  lua_pushliteral(L, "preload");             /* "package" T1 "preload" */
  lua_newtable(L);                           /* "package" T1 "preload" T2 */
  lua_pushliteral(L, "socket.core");         /* ... T2 name */
  lua_pushcfunction(L, luaopen_socket_core); /* ... T2 name func */
  lua_settable(L, -3);                       /* ... T2 */
  lua_pushliteral(L, "mime.core");           /* ... T2 name */
  lua_pushcfunction(L, luaopen_mime_core);   /* ... T2 name func */
  lua_settable(L, -3);                       /* "package" T1 "preload" T2 */
  lua_settable(L, -3);                       /* "package" T1 */
  lua_settable(L, LUA_GLOBALSINDEX);         /* */
  return 0;
}
%%%

cc -I$HOME/usrc/lua-5.0.2/include/ -I$HOME/usrc/lua-5.0.2/src/ \
  -DLUA_USERCONFIG='"preload_socket.c"'     \
  -DLUA_EXTRALIBS="{NULL, preload_socket}," \
  -c -o luasocket.o lua.c

cd ~/usrc/lua-5.0.2/src/lua/
cc -o ../../bin/luasocket  luasocket.o -L../../lib \
  -llua -llualib -lluasocket -lm -ldl

#----
#
# Luasocket: install ".lua"s in ~/.lua50/
# (We don't use the ".so"s)
# See: http://www.cs.princeton.edu/~diego/professional/luasocket/installation.html
#
#----

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/

#----
#
# Lua: install the binaries (lua, luac, luasocket) in ~/bin/
#
#----

cd ~/bin/
ln -sf ../usrc/lua-5.0.2/bin/lua .
ln -sf ../usrc/lua-5.0.2/bin/luac .
ln -sf ../usrc/lua-5.0.2/bin/luasocket .

#----
#
# luasocket: a test (just check if, e.g., "try" gets loaded)
#
#----

export LUA_INIT="@$HOME/.lua50/compat-5.1.lua"
export  LUA_PATH="$HOME/.lua50/?.lua;?.lua"
export LUA_CPATH="$HOME/.lua50/?.dll;?.dll"

luasocket -e '
  require "socket"
  pt = function(str, T) for k,v in T do print(str, k, v) end end
  pt("socket", socket)
'


TinyFTP.lua/MyFTP.lua

Why: see http://angg.twu.net/w32.html.

Code:

A minimal HTTP server written in LuaSocket

RFCs about http: rfc1945, e-script

Inspired by dustmote.

Status: not working yet...