Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
#######
#
# E-scripts on Lua (old stuff that I'm almost throwing away)
#
# Note 1: use the eev command (defined in eev.el) and the
# ee alias (in my .zshrc) to execute parts of this file.
# Executing this file as a whole makes no sense.
# An introduction to eev can be found here:
#
#   (find-eev-quick-intro)
#   http://angg.twu.net/eev-intros/find-eev-quick-intro.html
#
# Note 2: be VERY careful and make sure you understand what
# you're doing.
#
# Note 3: If you use a shell other than zsh things like |&
# and the for loops may not work.
#
# Note 4: I always run as root.
#
# Note 5: some parts are too old and don't work anymore. Some
# never worked.
#
# Note 6: the definitions for the find-xxxfile commands are on my
# .emacs.
#
# Note 7: if you see a strange command check my .zshrc -- it may
# be defined there as a function or an alias.
#
# Note 8: the sections without dates are always older than the
# sections with dates.
#
# This file is at <http://angg.twu.net/e/lua-old.e>
#           or at <http://angg.twu.net/e/lua-old.e.html>.
#        See also <http://angg.twu.net/emacs.html>,
#                 <http://angg.twu.net/.emacs[.html]>,
#                 <http://angg.twu.net/.zshrc[.html]>,
#                 <http://angg.twu.net/escripts.html>,
#             and <http://angg.twu.net/>.
#
#######





# «.lua-4.0_debs»	(to "lua-4.0_debs")
# «.lua_4.0-0»		(to "lua_4.0-0")
# «.lua_4.0-0.2»	(to "lua_4.0-0.2")
# «.lua_4.0-0.2:libdllua»  (to "lua_4.0-0.2:libdllua")
# «.lua_4.0-0.2:dllua.h»   (to "lua_4.0-0.2:dllua.h")
# «.lua_4.0-0.2:dllua.c»   (to "lua_4.0-0.2:dllua.c")
# «.lua_4.0-0.2:generic»   (to "lua_4.0-0.2:generic")
# «.lua_4.0-0.2:dltest1»   (to "lua_4.0-0.2:dltest1")
# «.lua_4.0-0.2:dltest2»   (to "lua_4.0-0.2:dltest2")
# «.lua_4.0-0.2:dltest2g»  (to "lua_4.0-0.2:dltest2g")

# «.dllua»		(to "dllua")
# «.dllua-patch»	(to "dllua-patch")
# «.lua_4.0-0.1»	(to "lua_4.0-0.1")
# «.loadlib-registerC»	(to "loadlib-registerC")
# «.loadlib-gdb»	(to "loadlib-gdb")




#####
#
# Lua-4.0: making a serious Debian package (lua_4.0-0)
# 2001jan08
#
#####

# «lua-4.0_debs»  (to ".lua-4.0_debs")
# «lua_4.0-0»  (to ".lua_4.0-0")
# This block produces the .deb (and the .dsc, the .diff.gz, etc) that
# I upload to my apt repository, from the pristine sources and a few
# extra files. If we uncomment a certain "patch" command this will
# produce debs for lua having my experimental "loadlib" command; these
# debs are never uploaded to the repository.
# How to fetch the debianized stuff and install it:
#		(to "fetching_the_debs")
# An older debianization attempt:
#		(to "lua_yada")
# The current debianization attempt, newer than this one:
#		(to "dllua-patch")
# The "source" for the debian/packages file:
#		(to "lua-packagesfile")
#*
rm -Rv /usr/src/lua_4.0*

rm -Rv /usr/src/lua-4.0.orig/
mkdir  /usr/src/lua-4.0.orig/
cd     /usr/src/lua-4.0.orig/
tar -xvzf $S/ftp/ftp.tecgraf.puc-rio.br/pub/lua/lua-4.0.tar.gz
mv -v lua/* .
rmdir lua/

rm -Rv /usr/src/lua-4.0/
mkdir  /usr/src/lua-4.0/
cd     /usr/src/lua-4.0/
tar -xvzf $S/ftp/ftp.tecgraf.puc-rio.br/pub/lua/lua-4.0.tar.gz
mv -v lua/* .
rmdir lua/

mkdir rttpatch
cd rttpatch
unzip $S/http/www.cl.cam.ac.uk/users/rrt1001/lualibs.zip
mv README README.rttpatch
for i in $(find * -type f); do mv -v $i ../$i; done
cd /usr/src/lua-4.0/
rm -Rv rttpatch

# (find-luafile "INSTALL" "Edit \"config\"")
# (find-luafile "config")

# My VERY EXPERIMENTAL version of loadlib for lua-4.0:
# (to "loadlib-patch")
# (find-angg "LUA/loadlib/")
# (find-angg "LUA/loadlib/README.loadlib")
# (find-angg "LUA/loadlib/lloadlib.c")
cp -v ~/LUA/loadlib/README.loadlib .
cp -v ~/LUA/loadlib/loadlib.patch .
cp -v ~/LUA/loadlib/lloadlib.c src/lib/
#patch -p0 < loadlib.patch

#*
#echo skipping patch -p0 config <<'%%%'
patch -b -p0 config <<'%%%'
96c96,97
< CFLAGS= -O2 $(WARN) $(INCS) $(DEFS)
---
> #CFLAGS= -O2 $(WARN) $(INCS) $(DEFS)
> CFLAGS= -g -O2 $(WARN) $(INCS) $(DEFS)
%%%

# Leave the stripping for dh_strip, we want debuggable binaries in
# <lua-dir>/bin/ and <lua-dir>/lib/.
patch -p0 Makefile <<'%%%'
22c22,23
< install: all strip
---
> #install: all strip
> install: all
%%%

# (find-fline "~/lua-4.0/debian/")
# (find-fline "/usr/bin/yada" "Wile E. Coyote")
# (find-es "debiandev" "yada")
mkdir debian
for i in debian/packages debian/changelog doc/lua.texi; do
  cp -av ~/lua-4.0/$i $i
done

yada yada
debian/yada rebuild rules

# dpkg-buildpackage -us -uc	|& tee /tmp/odbp

cat > $EEG <<'---'
TestPasswd
TestPasswd
---
eeg dpkg-buildpackage		|& tee /tmp/odbp

mv -v /tmp/odbp /usr/src/lua-4.0/
laf /usr/src/lua_4.0*
# (find-fline "/usr/src/" "lua_4.0")
# (find-luafile "debian/tmp-lua/")

#*
cd /usr/src/
mv -v lua*.deb .debs/
mv -v lua*.dsc     .dscs/
mv -v lua*.gz      .dscs/
mv -v lua*.changes .dscs/
aptu-local-i386

#*
#dpkg -i /usr/src/lua_4.0-0_i386.deb
dpkg -i /usr/src/.debs/lua_4.0-0_i386.deb

# (find-status "lua")
# (find-vldifile "lua.list")
# (find-fline "/usr/doc/lua/")


#*
# And these are for when I've compiled Lua with the loadlib patch:
cp -iv /usr/src/lua_4.0-0_i386.deb ~/LUA/loadlib/
#*
dpkg -i ~/LUA/loadlib/lua_4.0-0_i386.deb
lua -e 'print(loadlib)'
#*





#####
#
# Another "serious" Debian package, with cgilua's loadlib (lua-4.0-0.2)
# 2001jul26
#
#####

# «lua_4.0-0.2»  (to ".lua_4.0-0.2")
# (to "cgilua")
#*
rm -Rv /usr/src/lua_4.0*
cd /usr/src/
cp -iv .dscs/lua_4.0-0.dsc       .
cp -iv .dscs/lua_4.0.orig.tar.gz .
cp -iv .dscs/lua_4.0-0.diff.gz   .
dpkg-source -x lua_4.0-0.dsc

cd /usr/src/lua-4.0/

## «lua_4.0-0.2:libdllua»  (to ".lua_4.0-0.2:libdllua")
## First we prepare things to generate also a "libdllua.a", that
## comprises the "loadlib" functions from cgilua and my dllua_open...

rm -v README.loadlib loadlib.patch src/lib/lloadlib.c
cd /usr/src/lua-4.0/ && rm -v $(find * | grep orig)

B=-b
#B=

mkdir src/libdllua/
cp -v /usr/src/cgilua/loadlib/loadlib.{c,h} src/libdllua/

 # (find-luafile "src/libdllua/Makefile")
cat > src/libdllua/Makefile <<'---'
# makefile for libdllua standard library
#
LUA= ../..
LIB= $(LUA)/lib
LIBDLLUA= $(LUA)/libdllua
include $(LUA)/config
#
DLLUA_OBJS= loadlib.o dllua_open.o
DLLUA_SRCS= loadlib.o dllua_open.o
DLLUA_T= $(LIB)/libdllua.a
#
all: $(DLLUA_T)
$(DLLUA_T): $(DLLUA_OBJS)
	$(AR) $@ $(DLLUA_OBJS)
	$(RANLIB) $@
loadlib.o: loadlib.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -DDLFCN -o $@ $<
clean:
	rm -f $(DLLUA_OBJS) $(DLLUA_T)
---

 # (find-fline "~/LUA/loadlib/")
 # (find-luafile "src/lib/")
#cat > src/lib/dllua_open.c <<'---'
cat > src/libdllua/dllua_open.c <<'---'
#include "dllua.h"
lua_State *dllua_open(int stacksize) {
  lua_State *L = lua_open(stacksize);
  lua_baselibopen(L);
  lua_iolibopen(L);
  lua_strlibopen(L);
  lua_mathlibopen(L);
  lua_dblibopen(L);
  /* non-standard libraries */
  lua_rexlibopen(L);
  lua_bitlibopen(L);
  loadlib_open(L);
  return L;
}
---


## «lua_4.0-0.2:dllua.h»  (to ".lua_4.0-0.2:dllua.h")
## A ".h" to make a bit simpler to create C extensions.

 # (find-luafile "src/lib/")
 # (find-luafile "src/lib/loadlib.c")
 # (find-luafile "src/lib/loadlib.h")
cat > include/dllua.h <<'---'
#ifndef dllua_h
#define dllua_h
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
void loadlib_open( lua_State *L );
lua_State *dllua_open(int stacksize);
#endif
---


## «lua_4.0-0.2:dllua.c»  (to ".lua_4.0-0.2:dllua.c")
## From lua.c (i.e., from a slightly patched version of it) we will
## generate two ".o"s, the usual one and a "dllua.o" that links with
## the extra libs...

 # (find-luafile "src/lua/lua.c")
patch $B -p0 src/lua/lua.c <<'%%%'
315a316
> #ifndef DLLUA
317a319,321
> #else
>   L = dllua_open(opt.stacksize);
> #endif
%%%

 # (find-luafile "src/lua/Makefile")
patch $B -p0 src/lua/Makefile <<'%%%'
14c14,18
< all: $T
---
> DLLUA_OBJS= dllua.o
> DLLUA_SRCS= dllua.c
> DLLUA_T= $(BIN)/dllua
>
> all: $T $(DLLUA_T)
18a23,28
> $(DLLUA_T): $(DLLUA_OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a $(LIB)/libdllua.a
> 	$(CC) -o $@ $(DLLUA_OBJS) -L$(LIB) -llua -llualib -ldllua -ldl $(EXTRA_LIBS)
>
> dllua.o: lua.c
> 	$(CC) -c $(CPPFLAGS) $(CFLAGS) -DDLLUA -o $@ $<
>
23a34,36
>
> $(LIB)/libdllua.a:
> 	cd ../libdllua; $(MAKE)
%%%



## «lua_4.0-0.2:generic»  (to ".lua_4.0-0.2:generic")
## The files that control everything

patch $B -p0 Makefile <<'%%%'
14a15
> 	cd src/libdllua; $(MAKE) $@
34c35,38
< 	cd lib; ln -s liblua.so.$V liblua.so; ln -s liblualib.so.$V liblualib.so
---
> 	ld -o lib/libdllua.so.$V -shared src/libdllua/*.o
> 	cd lib; ln -s liblua.so.$V liblua.so
> 	cd lib; ln -s liblualib.so.$V liblualib.so
> 	cd lib; ln -s libdllua.so.$V libdllua.so
38c42
< 	rm -f bin/lua bin/luac
---
> 	rm -f bin/lua bin/luac bin/dllua
%%%

patch $B -p0 debian/packages <<'%%%'
21a22,23
>  rm                    inst/lib/libdllua.so
>  ln -s libdllua.so.4.0 inst/lib/libdllua.so
%%%

# (find-luafile "debian/changelog")
cat > debian/changelog <<'---'
lua (4.0-0.2) unstable; urgency=low

  * Second public Debian version (still quite unofficial).
    The script that makes the Debian package from the original sources can
    be found at <http://angg.twu.net/e/lua.e.html#lua_4.0-0.2>.

 -- Eduardo Ochs <edrx@mat.puc-rio.br>  Mon,  8 Jan 2001 18:16:54 -0200
---


rm -fv debian/control debian/rules debian/yada
rm -fv debian/files debian/substvars
yada yada
yada rebuild rules
yada rebuild control


# (find-luafile "src/libdllua/")
cd /usr/src/lua-4.0/

# debian/rules binary		|& tee odrb
# (find-luafile "odrb")
#
cat > $EEG <<'---'
TestPasswd
TestPasswd
---
eeg dpkg-buildpackage		|& tee /tmp/odbp
mv -v /tmp/odbp /usr/src/lua-4.0/

laf /usr/src/lua_4.0*
# (find-fline "/usr/src/" "lua_4.0")
# (find-luafile "debian/tmp-lua/")

cd /usr/src/
mv -v lua*.dsc     /usr/src/lua-4.0/
mv -v lua*.gz      /usr/src/lua-4.0/
mv -v lua*.deb     /usr/src/lua-4.0/
mv -v lua*.changes /usr/src/lua-4.0/

#*
cd /usr/src/lua-4.0/
cp -iv lua_4.0-0.2.dsc     ../.dscs/
cp -iv lua_4.0-0.2.diff.gz ../.dscs/

#*
rm -Rv /usr/src/lua*
pdsc /usr/src/.dscs/lua_4.0-0.2.dsc
cd /usr/src/lua-4.0/ && rm -v $(find * | grep orig)

#*
# «lua_4.0-0.2:dltest1»  (to ".lua_4.0-0.2:dltest1")
# (find-es "anatocc" "dlopen")
cd /tmp/
cat > mylualib.c <<'---'
#include <stdio.h>
void distant() {
  printf("Hello! Hello!\n");
}
---
gcc -g -Wall -shared -o mylualib.so mylualib.c

LD_LIBRARY_PATH=/usr/src/lua-4.0/lib \
  /usr/src/lua-4.0/bin/dllua -e '
    libhandle, err = loadlib("/tmp/mylualib.so")
    print(libhandle, err)
    callfromlib(libhandle, "distant")
    print("Hello")
  '

#*
# «lua_4.0-0.2:dltest2»  (to ".lua_4.0-0.2:dltest2")
# Second test: now we register a C function in Lua.
cd /tmp/
cat > mylualib.c <<'---'
#include <stdio.h>
/* #include <lualib.h> */
#include <dllua.h>
static int dipsy(lua_State *L) {
  printf("Dipsy!\n");
  return 0;
}

void distant_init(lua_State *L) {
  lua_register(L, "dipsy", dipsy);
}
---
gcc -g -Wall -shared -o mylualib.so mylualib.c

cat > /tmp/test.lua <<'---'
libhandle, err = loadlib("/tmp/mylualib.so")
print(libhandle, err)
callfromlib(libhandle, "distant_init")
print("Hello")
dipsy()
---

LD_LIBRARY_PATH=/usr/src/lua-4.0/lib \
  /usr/src/lua-4.0/bin/dllua /tmp/test.lua

#*
# «lua_4.0-0.2:dltest2g»  (to ".lua_4.0-0.2:dltest2g")
# (find-luafile "src/libdllua/loadlib.c")
# (gdbk-gdb 'eeg-bounded "/usr/src/lua-4.0/bin/dllua")
set args /tmp/test.lua
set env LD_LIBRARY_PATH /usr/src/lua-4.0/lib
br main
run
info share
# br loadlib_open
br loadlib.c:loadlib

#*





#####
#
# dllua: lua with the "loadlib" patch and something more
# 2001jun18
#
#####

# (find-luafile "")
# (find-luafile "README.rttpatch")
# (find-luafile "src/lib/lrexlib.c")
# (find-fline "~/tmp/lua-manual.txt" "5 - The Appli")
# (find-fline "~/tmp/lua-manual.txt" "5.13 - Defining C Functions")
# (find-w3 "/usr/doc/lua/manual.html#5.")
# (find-es "anatocc" "dlopen")
#*
# «dllua»  (to ".dllua")
# «dllua-patch»  (to ".dllua-patch")
# «lua_4.0-0.1»  (to ".lua_4.0-0.1")
# (to "lua-4.0_debs")

rm -R /usr/src/lua_4.0*

rm -R /usr/src/lua-4.0.orig/
mkdir  /usr/src/lua-4.0.orig/
cd     /usr/src/lua-4.0.orig/
tar -xzf $S/ftp/ftp.tecgraf.puc-rio.br/pub/lua/lua-4.0.tar.gz
mv -v lua/* .
rmdir lua/

rm -Rv /usr/src/lua-4.0/
mkdir  /usr/src/lua-4.0/
cd     /usr/src/lua-4.0/
tar -xzf $S/ftp/ftp.tecgraf.puc-rio.br/pub/lua/lua-4.0.tar.gz
mv -v lua/* .
rmdir lua/

mkdir rttpatch
cd rttpatch
unzip $S/http/www.cl.cam.ac.uk/users/rrt1001/lualibs.zip
mv README README.rttpatch
for i in $(find * -type f); do mv -v $i ../$i; done
cd /usr/src/lua-4.0/
rm -Rv rttpatch

# (find-luafile "INSTALL" "Edit \"config\"")
# (find-luafile "config")

#echo not doing patch -p0 config <<'%%%'
patch -b -p0 config <<'%%%'
96c96,97
< CFLAGS= -O2 $(WARN) $(INCS) $(DEFS)
---
> #CFLAGS= -O2 $(WARN) $(INCS) $(DEFS)
> CFLAGS= -g -O2 $(WARN) $(INCS) $(DEFS)
%%%

# (find-fline "~/lua-4.0/debian/")
# (find-fline "/usr/bin/yada" "Wile E. Coyote")
# (find-es "debiandev" "yada")
mkdir debian
for i in debian/packages debian/changelog doc/lua.texi; do
  cp -av ~/lua-4.0/$i $i
done



# (to "loadlib-patch")
# (find-angg "LUA/loadlib/")
cp -v ~/LUA/loadlib/README.loadlib .
cp -v ~/LUA/loadlib/loadlib.patch .
cp -v ~/LUA/loadlib/lloadlib.c src/lib/
cp -v ~/LUA/loadlib/dllualib.c src/lib/
cp -v ~/LUA/loadlib/dllua.h include/
#patch -p0 < loadlib.patch

# (find-fline "~/LUA/loadlib/loadlib.patch")
# (find-luafile "config")
# (find-luafile "include/lualib.h")
# (find-luafile "src/lib/Makefile")

# Leave the stripping for dh_strip, we want debuggable binaries in
# <lua-dir>/bin/ and <lua-dir>/lib/.

 # (find-luafile "src/lua/lua.c")
patch -b -p0 src/lua/lua.c <<'%%%'
315a316
> #ifndef DLLUA
317a319,321
> #else
>   L = dllua_open(opt.stacksize);
> #endif
%%%

 # (find-luafile "src/lib/Makefile")
patch -b -p0 src/lib/Makefile <<'%%%'
15c15,16
< T= $(LIB)/liblualib.a
---
> OBJS_DL= $(OBJS) lloadlib.o dllualib.o
> SRCS_DL= $(SRCS) lloadlib.c dllualib.c
17c18
< all: $T
---
> all: $(LIB)/liblualib.a $(LIB)/libdllua.a
19c20
< $T: $(OBJS)
---
> $(LIB)/liblualib.a: $(OBJS)
22a24,27
> $(LIB)/libdllua.a: $(OBJS_DL)
> 	$(AR) $@ $(OBJS_DL)
> 	$(RANLIB) $@
>
24c29
< 	rm -f $(OBJS) $T
---
> 	rm -f $(OBJS) $(LIB)/liblualib.a $(LIB)/libdllua.a
%%%

 # (find-luafile "src/lua/Makefile")
patch -b -p0 src/lua/Makefile <<'%%%'
9c9
< OBJS= lua.o
---
> OBJS= lua.o dllua.o
12c12
< T= $(BIN)/lua
---
> all: $(BIN)/lua $(BIN)/dllua
14c14,15
< all: $T
---
> $(BIN)/lua: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a
> 	$(CC) -o $@ lua.o -L$(LIB) -llua -llualib -ldl $(EXTRA_LIBS)
16,17c17,24
< $T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a
< 	$(CC) -o $@ $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS)
---
> # (find-node "(make)Catalogue of Rules")
> # (find-node "(make)Automatic")
>
> dllua.o: lua.c
> 	$(CC) -c $(CPPFLAGS) $(CFLAGS) -DDLLUA -o $@ $<
>
> $(BIN)/dllua: $(OBJS) dllua.o $(LIB)/liblua.a $(LIB)/liblualib.a
> 	$(CC) -o $@ dllua.o -L$(LIB) -llua -ldllua -ldl $(EXTRA_LIBS)
%%%

 # (find-luafile "Makefile")
patch -b -p0 Makefile <<'%%%'
22c22,23
< install: all strip
---
> #install: all strip
> install: all
28a30,35
> LUALIB_OBJS = src/lib/lauxlib.o src/lib/lbaselib.o	\
> 	src/lib/lbitlib.o src/lib/ldblib.o src/lib/liolib.o	\
> 	src/lib/lloadlib.o src/lib/lmathlib.o			\
> 	src/lib/lrexlib.o src/lib/lstrlib.o
> LUALIB_OBJS_DL = src/lib/dllualib.o
>
32,33c39,43
< 	ld -o lib/liblualib.so.$V -shared src/lib/*.o
< 	cd lib; ln -s liblua.so.$V liblua.so; ln -s liblualib.so.$V liblualib.so
---
> 	ld -o lib/liblualib.so.$V -shared $(LUALIB_OBJS)
> 	ld -o lib/libdllua.so.$V -shared $(LUALIB_OBJS)
> 	cd lib; ln -s liblua.so.$V liblua.so
> 	cd lib; ln -s liblualib.so.$V liblualib.so
> 	cd lib; ln -s libdllua.so.$V libdllua.so
%%%

patch -b -p0 include/lualib.h <<'%%%'
27a28
> LUALIB_API void lua_loadlib_open (lua_State *L);
%%%

 # (find-luafile "debian/changelog")
patch -b -p0 debian/changelog <<'%%%'
0a1,7
> lua (4.0-0.1) unstable; urgency=low
>
>   * Added a texinfo version of the manual; added dllua (see
>     <http://angg.twu.net/e/lua.e.html#dllua>).
>
>  -- Eduardo Ochs <edrx@mat.puc-rio.br>  Tue, 26 Jun 2001 22:00:00 -0200
>
%%%

yada yada
debian/yada rebuild rules
#*
debian/rules binary	|& tee odrb

#*
cat > $EEG <<'---'
TestPasswd
TestPasswd
---
eeg dpkg-buildpackage		|& tee /tmp/odbp

mv -v /tmp/odbp /usr/src/lua-4.0/
laf /usr/src/lua_4.0*
# (find-fline "/usr/src/" "lua_4.0")

#*
cd /usr/src/
mv -v lua*.deb .debs/
mv -v lua*.dsc     .dscs/
mv -v lua*.gz      .dscs/
mv -v lua*.changes .dscs/
aptu-local-i386

#*
chdir "/usr/src/lua-4.0/"
# (gdbk-perldb t "/usr/bin/" "dpkg-parsechangelog" t)
# (gdbk-perldb t "/usr/lib/dpkg/parsechangelog/debian < debian/changelog" "" t)
# (find-angg "eegdb.el" "gdbk-hyperlinks")
# (find-man "perlop" "The null filehandle <>")
# (find-fline "/usr/lib/dpkg/parsechangelog/debian")

#*

dpkg -i /usr/src/lua_4.0-0.1_i386.deb
#dpkg -i /usr/src/.debs/lua_4.0-0.1_i386.deb
#luae 'px(loadlib)'
dllua ~/LUA/inc.lua -e 'px(loadlib)'

#*










#*
# First test of the new lua:
# (find-es "anatocc" "dlopen")
cd /tmp/
cat > mylualib.c <<'---'
#include <stdio.h>
void distant() {
  printf("Hello! Hello!\n");
}
---
gcc -g -Wall -shared -o mylualib.so mylualib.c

luae '
  loadlib("/tmp/mylualib.so", "distant")
  print("Hello")
'

#*
# «loadlib-registerC»  (to ".loadlib-registerC")
# Second test: now we register a C function in Lua.
# (find-man "dlopen" "If  dlopen fails for any reason")

cd /tmp/
cat > mylualib.c <<'---'
#include <stdio.h>
#include <dllua.h>
static int dipsy(lua_State *L) {
  printf("Dipsy!\n");
  return 0;
}
void distant_init(lua_State *L) {
  printf("Init!\n");
  lua_register(L, "dipsy", dipsy);
}
---
gcc -g -Wall -shared -llua -o mylualib.so mylualib.c

# Note: if we omit the "-llua" above then weird things happen: dlopen
# returns NULL but gdb says that mylualib.so was loaded; and dlerror()
# returns "Success". Argh.

cat > /tmp/test.lua <<'---'
loadlib("/tmp/mylualib.so", "distant_init")
print("Hello")
dipsy()
---
dllua /tmp/test.lua

# LD_LIBRARY_PATH=/usr/src/lua-4.0/lib \
#   /usr/src/lua-4.0/bin/dllua /tmp/test.lua

#*
# «loadlib-gdb»  (to ".loadlib-gdb")
# (gdbk-gdb t "/usr/src/lua-4.0/bin/dllua")
set args /tmp/test.lua
set env LD_LIBRARY_PATH /usr/src/lua-4.0/lib
br main
run
info share
br loadlib
#*

# (find-status "lua")
# (find-vldifile "lua.list")
# (find-fline "/usr/doc/lua/")






#####
#
# Adding my version of "loadlib" to lua-4.0
# 2001feb21
#
#####

# (find-luafile "")
# (find-luafile "README.rttpatch")
# (find-luafile "src/lib/lrexlib.c")
# (find-fline "~/tmp/lua-manual.txt" "5 - The Appli")
# (find-fline "~/tmp/lua-manual.txt" "5.13 - Defining C Functions")
# (find-w3 "/usr/doc/lua/manual.html#5.")
# (find-es "anatocc" "dlopen")
#*
# «loadlib-patch»  (to ".loadlib-patch")
# (to "lua-4.0_debs")
cd /usr/src/lua-4.0/

patch -b -p0 config <<'%%%'
59c59
< EXTRA_LIBS= -lm
---
> EXTRA_LIBS= -lm -ldl
%%%
patch -b -p0 src/lib/Makefile <<'%%%'
11c11
<       lrexlib.o
---
>       lrexlib.o lloadlib.o
13c13
<       lrexlib.c
---
>       lrexlib.c lloadlib.c
%%%
patch -b -p0 include/lualib.h <<'%%%'
27a28
> LUALIB_API void lua_loadlib_open (lua_State *L);
%%%
patch -b -p0 src/lua/lua.c <<'%%%'
59a60
>   lua_loadlib_open(L);
%%%

#*
cd /usr/src/lua-4.0/
for i in config include/lualib.h src/lib/Makefile src/lua/lua.c; do
  diff -u $i.orig $i
done | tee ~/o
#cp ~/o ~/LUA/loadlib/loadlib.patch

# (find-angg "LUA/loadlib/")
# (find-angg "LUA/loadlib/README.loadlib")
# (find-angg "LUA/loadlib/lloadlib.c")

#*
# First test of the new lua:
# (find-es "anatocc" "dlopen")
cd /tmp/
cat > mylualib.c <<'---'
#include <stdio.h>
void distant() {
  printf("Hello! Hello!\n");
}
---
gcc -g -Wall -shared -o mylualib.so mylualib.c

LD_LIBRARY_PATH=/usr/src/lua-4.0/lib \
/usr/src/lua-4.0/bin/dllua -e '
  libhandle, err = loadlib("/tmp/mylualib.so")
  print(libhandle, err)
  callfromlib(libhandle, "distant")
  print("Hello")
'

# /usr/src/lua-4.0/bin/lua -e '
#   loadlib("/tmp/mylualib.so", "distant")
#   print("Hello")
# '

#*
# «loadlib-registerC»  (to ".loadlib-registerC")
# Second test: now we register a C function in Lua.

cd /tmp/
cat > mylualib.c <<'---'
#include <stdio.h>
#include <lualib.h>
static int dipsy(lua_State *L) {
  printf("Dipsy!\n");
  return 0;
}

void distant_init(lua_State *L) {
  lua_register(L, "dipsy", dipsy);
}
---
gcc -g -Wall -shared -o mylualib.so mylualib.c

cat > /tmp/test.lua <<'---'
-- loadlib("/tmp/mylualib.so", "distant_init")
libhandle, err = loadlib("/tmp/mylualib.so")
print(libhandle, err)
callfromlib(libhandle, "distant_init")
print("Hello")
dipsy()
---

LD_LIBRARY_PATH=/usr/src/lua-4.0/lib \
  /usr/src/lua-4.0/bin/dllua /tmp/test.lua

#*
# «loadlib-gdb»  (to ".loadlib-gdb")
# (gdbk-gdb t "/usr/src/lua-4.0/bin/lua")
set args /tmp/test.lua
set env LD_LIBRARY_PATH /usr/src/lua-4.0/lib
br main
run
info share
br loadlib
#*





#####
#
# loadlib (original version by rborges, for lua3.2)
# 2001feb21
#
#####

# «loadlib»  (to ".loadlib")
# (find-fline "~/LUA/myloadlib.c")
#*
rm -Rv /usr/src/loadlib/
mkdir  /usr/src/loadlib/
cd     /usr/src/loadlib/
tar -xvzf $S/http/www.tecgraf.puc-rio.br/~rborges/loadlib/loadlib.tgz
make CFLAGS=-I/usr/src/lua3.2-3.2/include LUAINC=/usr/include |& tee om
gcc -E -I/usr/src/lua3.2-3.2/include loadlib.c > loadlib.E

# make LUAINC=/usr/include |& tee om

# Compilation problems with lua4.0.
# (code-c-d "luall" "/usr/src/loadlib/")
# (find-luallfile "")
# (find-luallfile "makefile")
# (find-luallfile "loadlib.c")
# (find-luallfile "loadlib.c" 166)
# (find-luallfile "loadlib.h")
# (find-luallfile "loadlib.E")
# (find-luallfile "loadlib.E" "static int gettag")
# (find-luallfile "om")
# (find-fline "/usr/include/lua.h")
# (find-fline "/usr/include/lualib.h")
# (find-fline "/usr/include/lauxlib.h" "luaL_arg_check")
# (find-luatag "luaL_argerror")
# (find-fline "~/tmp/lua-manual.txt")
# (find-luafile "")
# (find-luafile "src/lib/ldblib.c" "luaL_argerror(L, 2,")
# (find-lua3.2file "")
# (find-lua3.2file "src/lib/lstrlib.c" "luaL_arg_check")

#*
cd /usr/src/lua-4.0/ && (
  find * -name '*.[ch]' | sort > .files.ch
  etags $(<.files.ch)
)
cd /usr/src/lua3.2-3.2/ && (
  find * -name '*.[ch]' | sort > .files.ch
  etags $(<.files.ch)
)

#*




#####
#
# uploading the debs
# 2001feb25
#
#####

# «uploading_the_debs»  (to ".uploading_the_debs")
# Note that as things are still too alpha I do upload new versions
# without changing the version numbers of the debs. Shame on me,
# but...
# (find-fline "/usr/src/.dscs/lua_4.0-0.diff.gz")
# 2001jun26: Changed the version to 4.0-0.1.
#*
cd /usr/src/.dscs/
anonftp ftp://angg.twu.net/home2/edrx/slow_html/debian/dists/potato/local/ \
  'cd source'			\
  'put lua_4.0-0.1.diff.gz'	\
  'put lua_4.0-0.1.dsc'		\
  'put lua_4.0-0.1_i386.changes'	\
  'put lua_4.0.orig.tar.gz'	\
  'quit'

cd /usr/src/.debs/
anonftp ftp://angg.twu.net/home2/edrx/slow_html/debian/dists/potato/local/ \
  'cd binary-i386'		\
  'put lua_4.0-0.1_i386.deb'	\
  'quit'

cd ~/lua-4.0/doc/
anonftp ftp://angg.twu.net/home2/edrx/slow_html/lua-4.0/doc/ \
  'put lua.texi' quit

# (find-es "page" "apt_repository")
# (find-angg ".zshrc" "apt")
#*
# (eevt-bounded)
cd ~/slow_html/debian/
dpkg-scan_p+s dists/potato/local
(rm -Rv ~/public_html/debian/; cd ~/slow_html/; cp -dPpvRl * ~/public_html/)

#*
# (eevt-bounded)
cd ~/slow_html/debian/dists/potato/local/
l binary-i386/Packages source/Sources

#*










#  Local Variables:
#  coding:               utf-8-unix
#  End: