Warning: this is an htmlized version!
The original is across this link,
and the conversion rules are here.
#######
#
# E-scripts on Lua.
#
# 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.
#
# 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/lua5.e>
#           or at <http://angg.twu.net/e/lua5.e.html>.
#        See also <http://angg.twu.net/emacs.html>,
#                 <http://angg.twu.net/.zshrc[.html]>,
#                 <http://angg.twu.net/escripts.html>,
#             and <http://angg.twu.net/>.
#
#######



# «.install-5.0.2»	(to "install-5.0.2")
# «.install-5.1.1»	(to "install-5.1.1")
# «.install-5.1.2»	(to "install-5.1.2")
# «.install-5.1.3»	(to "install-5.1.3")
# «.minimal_GCW_SUGAR»	(to "minimal_GCW_SUGAR")
# «.compile-5.1.2-lua_O0»  (to "compile-5.1.2-lua_O0")
# «.install-5.1+ext»	(to "install-5.1+ext")
# «.build-simple»	(to "build-simple")
# «.build»		(to "build")
# «.argpatch»		(to "argpatch")
# «.argpatch-gdb»	(to "argpatch-gdb")
# «.argpatch-recompile»	(to "argpatch-recompile")

# «.lua50ref.e»		(to "lua50ref.e")
# «.lua50betaref.e»	(to "lua50betaref.e")
# «.invoking-arrays»	(to "invoking-arrays")
# «.string.find»	(to "string.find")
# «.string.gfind»	(to "string.gfind")
# «.emptycaptures»	(to "emptycaptures")
# «.0-based»		(to "0-based")
# «.vararg»		(to "vararg")
# «.lua-arg»		(to "lua-arg")
# «.pack-and-unpack»	(to "pack-and-unpack")
# «.envsubst»		(to "envsubst")
# «.readfile»		(to "readfile")
# «.writefile»		(to "writefile")
# «.mytostring»		(to "mytostring")
# «.split»		(to "split")
# «.for»		(to "for")
# «.each2»		(to "each2")
# «.require»		(to "require")
# «.lua5.1-require»	(to "lua5.1-require")
# «.lua5.1-package»	(to "lua5.1-package")

# «.loadlib2»		(to "loadlib2")
# «.luaL_openlib»	(to "luaL_openlib")
# «.pio_fontx»		(to "pio_fontx")
# «.mailing-list-archive»  (to "mailing-list-archive")
# «.hash»		(to "hash")

# «.io.output»		(to "io.output")
# «.vmmerge5.lua»	(to "vmmerge5.lua")
# «.vmmerge»		(to "vmmerge")
# «.suggestions»	(to "suggestions")
# «.tolua-5.0»		(to "tolua-5.0")
# «.tolua-5.1»		(to "tolua-5.1")
# «.etags»		(to "etags")
# «.readline»		(to "readline")
# «.stringtolines»	(to "stringtolines")
# «.luaposix»		(to "luaposix")
# «.posix-lua51»	(to "posix-lua51")
# «.posix»		(to "posix")
# «.posix-new»		(to "posix-new")
# «.posix-install»	(to "posix-install")
# «.load_posix»		(to "load_posix")
# «.posix-old»		(to "posix-old")
# «.pushglobals-poglobals»  (to "pushglobals-poglobals")
# «.gsub-with-alternatives»  (to "gsub-with-alternatives")
# «.C-calls-lua»	(to "C-calls-lua")
# «.luastackPP»		(to "luastackPP")
# «.composes»		(to "composes")
# «.stdlib»		(to "stdlib")
# «.stdlib2»		(to "stdlib2")
# «.ricilake-parser»	(to "ricilake-parser")
# «.reuben-thomas-libs»	(to "reuben-thomas-libs")
# «.compat-5.1»		(to "compat-5.1")
# «.cgilua»		(to "cgilua")
# «.quick-presentation»	(to "quick-presentation")
# «.string.gsub»	(to "string.gsub")
# «.makewith»		(to "makewith")
# «.pil»		(to "pil")
# «.pil2»		(to "pil2")
# «.luagtk»		(to "luagtk")
# «.luagtk_pixmaps»	(to "luagtk_pixmaps")

# «.bitlib»		(to "bitlib")
# «.bitlib-51»		(to "bitlib-51")
# «.rexlib»		(to "rexlib")
# «.io.popen»		(to "io.popen")
# «.txt2html_in_blogme»	(to "txt2html_in_blogme")
# «.xpcall-traceback»	(to "xpcall-traceback")
# «.luasocket-static-aix»  (to "luasocket-static-aix")
# «.luasocket-on-linux»	(to "luasocket-on-linux")
# «.luasocket-lua51»	(to "luasocket-lua51")
# «.lua2c»		(to "lua2c")
# «.calling-Lua-from-C»	(to "calling-Lua-from-C")
# «.monitored_p_C»	(to "monitored_p_C")
# «.debug.debug»	(to "debug.debug")
# «.getoutput»		(to "getoutput")
# «.signal»		(to "signal")
# «.captured-variables»	(to "captured-variables")
# «.objective-lua»	(to "objective-lua")
# «.tokenf»		(to "tokenf")
# «.ex»			(to "ex")
# «.xpcall»		(to "xpcall")
# «.metamethods-pseudocode»  (to "metamethods-pseudocode")
# «.generators-pseudocode»   (to "generators-pseudocode")
# «.pil24.1»		(to "pil24.1")
# «.pixeltoaster»	(to "pixeltoaster")
# «.compressing-jpgs»	(to "compressing-jpgs")
# «.matrix.lua»		(to "matrix.lua")
# «.lpeg»		(to "lpeg")
# «.lpeg-0.6»		(to "lpeg-0.6")
# «.lpeg-precaptures»	(to "lpeg-precaptures")
# «.lpeg-0.7»		(to "lpeg-0.7")
# «.lpeg-0.8.1»		(to "lpeg-0.8.1")
# «.lpeg-quickref»	(to "lpeg-quickref")
# «.lpeg-ex-arith-1»	(to "lpeg-ex-arith-1")
# «.lpeg-ex-arith-2»	(to "lpeg-ex-arith-2")
# «.lpeg-elisp-hyperlinks»  (to "lpeg-elisp-hyperlinks")
# «.sheadsymbol-roberto»    (to "sheadsymbol-roberto")
# «.lpeg-0.5-bug»	(to "lpeg-0.5-bug")
# «.loadstring_and_eof»	(to "loadstring_and_eof")
# «.incompletep»	(to "incompletep")
# «.ldb-from-tgz»	(to "ldb-from-tgz")
# «.ldb»		(to "ldb")
# «.lua-mode.el»	(to "lua-mode.el")
# «.risclua»		(to "risclua")
# «.functionnames»	(to "functionnames")
# «.cinvoke»		(to "cinvoke")
# «.cinvoke-libtcl»	(to "cinvoke-libtcl")
# «.tlbridge.c»		(to "tlbridge.c")
# «.luatclbridge»	(to "luatclbridge")
# «.lunatic-python»	(to "lunatic-python")
# «.kepler»		(to "kepler")
# «.helper-threads»	(to "helper-threads")
# «.loona»		(to "loona")
# «.pseudo-spreadsheet»	(to "pseudo-spreadsheet")
# «.CGI.lua»		(to "CGI.lua")
# «.kepler-1.1»		(to "kepler-1.1")
# «.kepler-1.1-hasbang»	(to "kepler-1.1-hasbang")
# «.markdown.lua»	(to "markdown.lua")
# «.ctrace»		(to "ctrace")
# «.coroutines»		(to "coroutines")
# «.chunkspy»		(to "chunkspy")
# «.mav»		(to "mav")
# «.lpeg-links-ascii-diags»  (to "lpeg-links-ascii-diags")
# «.lua-ex»		(to "lua-ex")
# «.lua-api-from-gdb»	(to "lua-api-from-gdb")
# «.lbci»		(to "lbci")
# «.numlua»		(to "numlua")
# «.clue»		(to "clue")
# «.reader»		(to "reader")
# «.interactor»		(to "interactor")
# «.interactor-prefixes»  (to "interactor-prefixes")
# «.debug.getinfo»	(to "debug.getinfo")
# «.metalua»		(to "metalua")
# «.setvbuf»		(to "setvbuf")
# «.luarocks»		(to "luarocks")
# «.lexpect»		(to "lexpect")
# «.shells-in-lua»	(to "shells-in-lua")
# «.coxpcall»		(to "coxpcall")
# «.elua-and-grub»	(to "elua-and-grub")
# «.elua»		(to "elua")
# «.apairs-and-print»	(to "apairs-and-print")
# «.LUA_COMPAT_VARARG»	(to "LUA_COMPAT_VARARG")
# «.coroutine-iterator»	(to "coroutine-iterator")
# «.modal.lua»		(to "modal.lua")
# «.lpeg.Cmt»		(to "lpeg.Cmt")
# «.lpeg.Cmt-2»		(to "lpeg.Cmt-2")
# «.preproc»		(to "preproc")
# «.ee_loadlib»		(to "ee_loadlib")
# «.shake»		(to "shake")





#####
#
# building lua-5.0.2 and installing it locally
# 2004jul31
#
#####

# Build with loadlib and readline, and without "-g", and install as:
#  ~/bin/lua50
#  ~/bin/luac50
#  ~/lib/liblua.so.5.0
#  ~/lib/liblualib.so.5.0
# Note that these lua50 and luac50 won't depend on the "liblib...so.5.0"s.

# http://www.lua.org/ftp/lua-5.0.2.tar.gz

# «install-5.0.2»  (to ".install-5.0.2")
# (code-c-d "lua5" "~/usrc/lua-5.0.2/")
# (code-c-d "luaftp" "$S/http/www.lua.org/ftp/")
# (find-luaftpfile "")
# (find-lua5file "")
# http://www.lua.org/ftp/
# http://www.lua.org/ftp/lua-5.0.2.tar.gz
# http://www.lua.org/ftp/lua-5.0.3.tar.gz
#*
mkdir  ~/usrc/
rm -Rv ~/usrc/lua-5.0.2/
mkdir  ~/usrc/lua-5.0.2/
tar -xvzf $S/http/www.lua.org/ftp/lua-5.0.2.tar.gz -C ~/usrc/
cd     ~/usrc/lua-5.0.2/

find * -name '*.[ch]' | sort > .files.ch
etags $(<.files.ch)

# (find-lua5file "INSTALL")
# (find-lua5file "config")
# (find-lua5file "etc/README")
# (find-lua5file "src/lib/loadlib.c")
cat >> config <<'%%%'

# --- Edrx's changes
# (find-lua5file "config" "dynamic loading on Unix systems")
LOADLIB= -DUSE_DLOPEN=1
DLLIB= -ldl
MYLDFLAGS= -Wl,-E
MYCFLAGS=-g
#
# (find-lua5file "config" "\n#USERCONF=")
USERCONF=-DLUA_USERCONFIG='"$(LUA)/etc/saconfig.c"' -DUSE_READLINE
EXTRA_LIBS= -lm -lreadline -ldl

INSTALL_EXEC= cp -v
INSTALL_DATA= cp -v
STRIP=echo NOT stripping:
INSTALL_BIN=$(HOME)/bin
INSTALL_INC=$(HOME)/include/lua5
INSTALL_LIB=$(HOME)/ulocal/lib
INSTALL_MAN=$(HOME)/ulocal/man/man1
%%%

make test	2>&1 | tee omt
ldd  bin/lua	2>&1 | tee ol
make so		2>&1 | tee oms
make install	2>&1 | tee omi
make soinstall	2>&1 | tee omsi
# (find-lua5file "om")
# (find-lua5file "omi")
# (find-lua5file "omsi")

#*
cd ~/usrc/lua-5.0.2/
cp -v bin/lua  ~/bin/lua50
cp -v bin/luac ~/bin/luac50
cp -v lib/liblua.so.5.0    ~/lib/liblua.so.5.0
cp -v lib/liblualib.so.5.0 ~/lib/liblualib.so.5.0

#*

#*
# (find-lua5file "src/lib/lmathlib.c")
# (find-efunction 'eegdb)
# (find-eev "eev-gud.el")
# (find-efunction 'eegud-gdb)
# (eegud-gdb t ee-luadir "bin/lua")
br luaopen_math
run

#*
cp bin/lua ~/bin/lua50noargpatch

#*



#####
#
# building lua-5.1.1
# 2006jul18
#
#####

# «install-5.1.1»  (to ".install-5.1.1")
# http://www.lua.org/ftp/lua-5.1.1.tar.gz
See below; it's the same as for installing 5.1.2, with some ".1"s in
place of the ".2"s.



#####
#
# building lua-5.1.2
# 2007apr04
#
#####

# «install-5.1.2»  (to ".install-5.1.2")
# http://www.lua.org/ftp/lua-5.1.2.tar.gz
# (code-c-d "lua51" "~/usrc/lua-5.1.2/")
# (find-lua51file "")
# (find-lua51file "INSTALL")
# (find-lua51file "oml")
# (find-lua51file "src/Makefile")
# (find-node "(make)Phony Targets" "`.PHONY'")
#*
mkdir   ~/usrc/
rm -Rfv ~/usrc/lua-5.1.2/
mkdir   ~/usrc/lua-5.1.2/
tar  -C ~/usrc/ -xvzf $S/http/www.lua.org/ftp/lua-5.1.2.tar.gz
cd      ~/usrc/lua-5.1.2/

find * -name '*.[ch]' | sort > .files.ch
etags $(<.files.ch)

# (find-angg "bin/patch-lua-5.1.3")

# (to "risclua")
# «minimal_GCW_SUGAR»  (to ".minimal_GCW_SUGAR")
# (find-lua51file "src/llex.c" "#ifdef GCW_SUGAR")
# (find-lua51file "src/llex.c.orig" "case '=':")
# (find-tkdiff (ee-lua51file "src/llex.c") (ee-lua51file "src/llex.c.orig"))
#
cp -iv src/llex.c src/llex.c.orig
patch -p0 src/llex.c <<'%%%'
370a371,376
> #ifdef GCW_SUGAR
>         switch(ls->current) {
>          case '=': next(ls); return TK_EQ; break;
>          case '>': next(ls); return TK_RETURN; break;
>          default: return '=';  } 
> #else
372a379
> #endif
373a381,386
> #ifdef GCW_SUGAR
>       case '\\': {
>         next(ls);
>         return TK_FUNCTION;
>         }
> #endif
%%%

# Pre-compile llex.c with GCW_SUGAR=1
# cd src; gcc -O2 -Wall -DLUA_USE_LINUX -DGCW_SUGAR -c -o llex.o llex.c; cd ..
# Instead:

# (find-lua51file "src/Makefile")
patch -p0 src/Makefile <<'%%%'
11c11
< CFLAGS= -O2 -Wall $(MYCFLAGS)
---
> CFLAGS= -O2 -Wall $(MYCFLAGS) -g $(MYEXTRACFLAGS) -DGCW_SUGAR
%%%

# «compile-5.1.2-lua_O0»  (to ".compile-5.1.2-lua_O0")
# (find-angg ".emacs" "eepitch-gdb-lua")
# This block (optional) produces an unoptimized "lua" - "lua_O0" - for gdb.
# Note that its last (=3rd) line is a "make clean"...
{ make linux test MYEXTRACFLAGS="-ggdb -O0"
  mv -v src/lua src/lua_O0
  make clean
} |& tee oml0

make linux test |& tee oml

# Make a .so
# (find-lua50file "Makefile" "so:")
# (find-lua51file "src/Makefile" "CORE_O=")
cd src; ld -o liblua.so -shared $(ar t liblua.a); cd ..

# (find-lua51file "oml")
# (find-lua51file "oml2")

#*
cd ~/usrc/lua-5.1.2/src/
cp -iv lua  ~/bin/lua51
cp -iv luac ~/bin/luac51

#*
# Test dlopen on lpeg
# (to "lpeg")
cd ~/usrc/lpeg-0.5/
~/usrc/lua-5.1.1/src/lua test.lua
~/usrc/lua-5.1.2/src/lua test.lua

#*



# (find-lua51file "src/Makefile")
# (find-lua51file "src/Makefile" "linux:")
# (find-lua51file "Makefile")
# (find-lua51file "oml")


make MYCFLAGS=-DGCW_SUGAR linux test |& tee oml




#####
#
# building lua-5.1.3
# 2008jul21
#
#####

# «install-5.1.3»  (to ".install-5.1.3")
# http://www.lua.org/ftp/lua-5.1.3.tar.gz
# (code-c-d "lua51" "~/usrc/lua-5.1.3/")
# (find-lua51file "")
# (find-lua51file "INSTALL")
# (find-lua51file "oml")
# (find-lua51file "src/Makefile")
# (find-node "(make)Phony Targets" "`.PHONY'")
#*
mkdir   ~/usrc/
rm -Rfv ~/usrc/lua-5.1.3/
mkdir   ~/usrc/lua-5.1.3/
tar  -C ~/usrc/ -xvzf $S/http/www.lua.org/ftp/lua-5.1.3.tar.gz
cd      ~/usrc/lua-5.1.3/

find * -name '*.[ch]' | sort > .files.ch   ;# (find-lua51file ".files.ch")
etags $(<.files.ch)			   ;# (find-lua51file "TAGS")
~/bin/patch-lua-5.1.3			   ;# (find-angg "bin/patch-lua-5.1.3")
make linux test local |& tee omltl	   ;# (find-lua51file "omltl")

cd src; ld -o liblua.so -shared $(ar t liblua.a); cd ..
cd src; install -p -m 0644 liblua.so ../lib; cd ..

#*
# (find-lua51file "Makefile")
# (find-lua51file "Makefile" "local:")
# (find-lua51file "")
# (find-lua51sh "find bin include lib man share | sort")

# I have not adapted this to lua-5.1.3 yet:
#   (find-es "lua5" "compile-5.1.2-lua_O0")





#####
#
# Rici Lake's lua-5.1+extensions
# 2006sep09
#
#####

# «install-5.1+ext»  (to ".install-5.1+ext")
# http://primero.ricilake.net/lua-5.1+extensions.tgz
# (find-fline "~/LOGS/2006sep08.lua" "lua-5.1+extensions.tgz")
# (code-c-d "lua51ext" "~/usrc/lua-5.1+extensions/")
# (find-lua51extfile "")
# (find-lua51extfile "README.patches")
# (find-lua51extfile "src/print.c" "static void PrintCodeRange")
# (find-lua51extfile "INSTALL")
# (find-lua51extfile "oml")
# (find-lua51extfile "src/")
# (find-lua51extfile "src/Makefile")
# (find-node "(make)Phony Targets" "`.PHONY'")
#*
mkdir   ~/usrc/
rm -Rfv ~/usrc/lua-5.1+extensions/
mkdir   ~/usrc/lua-5.1+extensions/
tar  -C ~/usrc/ -xvzf $S/http/primero.ricilake.net/lua-5.1+extensions.tgz
cd      ~/usrc/lua-5.1+extensions/

find * -name '*.[ch]' | sort > .files.ch
etags $(<.files.ch)

# (find-lua5file "INSTALL")
# (find-lua5file "config")
# (find-lua5file "etc/README")
# (find-lua5file "src/lib/loadlib.c")
cat >> config <<'%%%'

# --- Edrx's changes
# (find-lua5file "config" "dynamic loading on Unix systems")
LOADLIB= -DUSE_DLOPEN=1
DLLIB= -ldl
MYLDFLAGS= -Wl,-E
MYCFLAGS=-g
#
# (find-lua5file "config" "\n#USERCONF=")
USERCONF=-DLUA_USERCONFIG='"$(LUA)/etc/saconfig.c"' -DUSE_READLINE
EXTRA_LIBS= -lm -lreadline -ldl

INSTALL_EXEC= cp -v
INSTALL_DATA= cp -v
STRIP=echo NOT stripping:
INSTALL_BIN=$(HOME)/bin
INSTALL_INC=$(HOME)/include/lua5
INSTALL_LIB=$(HOME)/ulocal/lib
INSTALL_MAN=$(HOME)/ulocal/man/man1
%%%

make test	2>&1 | tee omt
ldd  bin/lua	2>&1 | tee ol
#make so	2>&1 | tee oms
#make install	2>&1 | tee omi
#make soinstall	2>&1 | tee omsi
# (find-lua5file "om")
# (find-lua5file "omi")
# (find-lua5file "omsi")

#*
make linux test |& tee oml

#*
cd ~/usrc/lua-5.1.1/src/
cp -iv lua  ~/bin/lua51
cp -iv luac ~/bin/luac51

#*





#####
#
# lua5.0beta with my patch to build `arg' before doing the options
# 2003jan18
#
#####

# «argpatch»  (to ".argpatch")
# (find-angg "LUA/lua50beta-argpatch.sh")
# (find-angg "LFORTH/README" "build-lua")
#*
rm -Rv ~/tmp/lua-5.0-beta/
mkdir  ~/tmp/lua-5.0-beta/
tar -xvzf $S/http/www.lua.org/ftp/lua-5.0-beta.tar.gz -C ~/tmp/
cd     ~/tmp/lua-5.0-beta/

# (find-lua50file "src/lua/lua.c" "other arguments; loop over them")
# (find-lua50file "src/lua/lua.c" "collect arguments")
# (find-lua50file "src/lua/lua.c" "lua.c-argpatch")
# (find-lua50file "src/lua/lua.c" "lua.c-argpatch2")
#
cp -iv src/lua/lua.c src/lua/lua.c.orig
cat ~/LUA/lua50beta-argpatch.sh
.   ~/LUA/lua50beta-argpatch.sh

# (find-lua50file "INSTALL")
# (find-lua50file "config")
# (find-lua50file "etc/README")
# (find-lua50file "etc/loadlib.c")
#
cat >> config <<'%%%'

# --- Edrx's changes
# (find-fline "config" "\n#USERCONF=")
USERCONF=-DLUA_USERCONFIG='"$(LUA)/etc/config.c"' -DUSE_READLINE -DUSE_LOADLIB
EXTRA_LIBS= -lm -lreadline -ldl
%%%

# To compile with debug information use the line with the `-g'.
make test
# make MYCFLAGS=-g test

# Ckeck if the patch works:
cd ~/tmp/lua-5.0-beta/
bin/lua -e 'print(arg and arg[1]) -- should print "foo"' /dev/null foo

cp bin/lua ~/bin/lua50argpatch

#*
# «argpatch-gdb»  (to ".argpatch-gdb")
set args -e 'print(arg and arg[1])' /dev/null foo
br handle_argv
run
p "argv[2]:"
p  argv[2]
p "argv[3]:"
p  argv[3]
# (eegud-gdb 'do-bounded "~/tmp/lua-5.0-beta/" "bin/lua")

#*
# «argpatch-recompile»  (to ".argpatch-recompile")
# (find-lua50file "src/lua/lua.c" "other arguments; loop over them")
# (find-lua50file "src/lua/lua.c" "collect arguments")
# (find-lua50file "src/lua/lua.c" "lua.c-argpatch")
# (find-lua50file "src/lua/lua.c" "lua.c-argpatch2")
cd ~/tmp/lua-5.0-beta/
touch src/lua/lua.c
make MYCFLAGS=-g test
bin/lua -e 'print(arg and arg[1])' /dev/null foo bar

#*




#####
#
# lua5.0: making an e-script version of the manual
# 2003jun29
#
#####

# «lua50ref.e»  (to ".lua50ref.e")
# (find-angg "LUA/lua50ref.e")
#*
lynx http://www.lua.org/ftp/
#*
gv $S/http/www.lua.org/ftp/refman-5.0.ps.gz &
#*
tar -tvzf $S/http/www.lua.org/ftp/lua-5.0.tar.gz
#*
cd $S/http/www.lua.org/ftp/
zcat refman-5.0.ps.gz | pstotext | tee refman-5.0.txt
# (find-fline "$S/http/www.lua.org/ftp/refman-5.0.txt")
#*
# (find-fline "~/LUA/lua50ref.e")
cp -iv $S/http/www.lua.org/ftp/refman-5.0.txt ~/LUA/lua50ref.e
#*

(find-shttpfile "www.lua.org/ftp/")
(find-es "lua5" "lua50ref.e")

(code-ps "lua50" "$S/http/www.lua.org/ftp/refman-5.0.ps.gz")
(find-lua50page 1)
emacs ~/LUA/lua50ref.e &

(progn
(fooi "’e" "é" "›c" "ç" "”a" "ã" "”o" "õ" "’o" "ó"
      "‘a" "à" "“a" "â" "’" "í" "’a" "á")
(fooi "Di#erent" "Different" "di#erent" "different" "o#cial" "official"
      "e#ects" "effects" "e#ectively" "effectively" "a#ecting" "affecting"
      " # " " -> " "a#ect" "affect" "e#cient" "efficient" "o#ers" "offers"
      "o#set" "offset" "di#erence" "difference" "turns o# " "turns off "
      "su#x" "suffix" "o#er" "offer")
(fooi "+ ­\n" "+ -\n" "MERCHANTABIL­\nITY" "MERCHANTABILITY"
      "proce­\ndural" "procedural" "auto­\nmatically" "automatically"
      "con­\ncatenation" "concatenation" "discus­\nsion" "discussion"
      "con­\nventional" "conventional" "assign­\nments" "assignments"
      "state­\nment" "statement" "arith­\nmetic" "arithmetic"
      "oper­\nadors" "operadors" "multipli­\ncation" "multiplication"
      "appro­\npriate" "appropriate" "garbage­\ncollection"
      "garbage-collection" "pseudo­\nindices" "pseudo-indices"
      "ready­\nto­use" "ready-to-use" "termi­\nnating" "terminating"
      "stan­\ndard" "standard" "imple­\nmented" "implemented"
      "mod­\nules" "modules" "ap­\nplication" "application"
      "char­\nacters" "characters" "repre­\nsents" "represents"
      "cap­\ntured" "captured" "nec­\nessary" "necessary"
      "genera­\ntor" "generator" "compil­\ners" "compilers"
      "de­\nscribing" "describing" "comple­\ntion" "completion"
      "unpro­\ntected" "unprotected" "pre­compile" "pre-compile"
      "re­\nturning" "returning" "oth­\nerwise" "otherwise"
      "mes­\nsage" "message" "pro­\ngrams" "programs" "func­\ntional"
      "functional" "corou­\ntines" "coroutines" "declara­\ntions"
      "declarations" "oper­\nators" "operators" "op­\neration"
      "operation" "com­\npared" "compared" "collec­\ntion"
      "collection" "trans­\nlates" "translates" "zero­\nterminated"
      "zero-terminated" "distribu­\ntion" "distribution"
      "environ­\nment" "environment" "infor­\nmation" "information"
      "pseudo­\nrandom" "pseudo-random" "de­\npends" "depends"
      "in­\nstead" "instead")
)

(progn
(fooi-re "\n\\([0-9]+\\)\n" "\n\n# «p\\1» (find-lua50page \\1)\n")
(fooi-re "§\\([0-9]+\\(\\.[0-9]+\\)*\\)" "(to \"sec\\1\")")
(save-excursion
  (ee-goto-position "\nIncompatibilities with")
  (fooi-re "\n\\([0-9]+\\(\\.[0-9]+\\)*\\) \\([A-Z][-­A-Za-z ]*\\)"
           "\n\n# «sec\\1»\n# «\\3»\n\n\\1 \\3\n")
  )
(save-excursion
  (ee-goto-position "\nStandard Libraries")
  (fooi-re "\n\n\\(\\. \\([a-zA-Z_.:]+\\)\\)"
           "\n\n# «\\2»\n\\1")
  )
(fooi-re "\n\\(``\\([a-z]*\\)'':\\)" "\n# «__\\2»\n\\1")
)

(ee-isearch "­\n")
(ee-isearch "­")
(fooi "­\n" "")
(fooi "­\n" "-")

(fooi "­" "-")

(fooi-re (concat "\n\\([0-9]+\\(?:\\.[0-9]+\\)*\\) \\([^\n]*\\)"
		 "\\(?: \\.\\)\\{7\\} \\([0-9]+\\)")
	 "\n\\1 \\2 \\3 (to \"sec\\1\")")



(progn (jump-to-register ?a) (ee-isearch "­\n"))

egrep '^[0-9]+$' ~/tmp/luaref.txt | l -S

#*
cd
tclsh ~/TH/Generate LUA/lua50ref.e.html "a2html LUA/lua50ref.e"
cp -v ~/LUA/lua50ref.e{,.html} ~/TH/L/LUA/
#*
lynx ~/TH/L/LUA/lua50ref.e.html
#*
cd ~/LUA/
echo 'l $passwd(puc)' > $EEG
Scp -C lua50ref.e{,.html} edrx@${SUCURI}:slow_html/LUA/
#*
cd ~/LUA/
anonftp angg.twu.net 'cd ~/slow_html/LUA/' \
  'put lua50ref.e' \
  'put lua50ref.e.html' \
  quit
#*
# Then do the usual "makepage"/"makepage; makeindexhtmls" at twu and
# at mat.puc-rio to copy from slow_html to public_html, and...
#
lynx "http://angg.twu.net/LUA/lua50ref.e.html#For Statement"
lynx "http://www.mat.puc-rio.br/~edrx/LUA/lua50ref.e.html#For Statement"





#####
#
# Invoking arrays
# 2003jan08
#
#####

# «invoking-arrays»  (to ".invoking-arrays")
# (find-lua50ref "__call")
# (find-lua50ref "setmetatable")
# (find-lua50ref "sec3.7")
#*
lua50 -e '
  arr = {}				-- (find-lua50ref "sec3.7")
  setmetatable(arr, arr)		-- (find-lua50ref "setmetatable")
  arr.__call = print			-- (find-lua50ref "__call")
  arr(20, 30, 40)			--> table:0xxxxxxxxx 20 30 40

  arr.name = "<arr>"
  arr.__call = function (arr, ...)
      print(arr.name, unpack(arg))
    end
  arr(20, 30, 40)			--> <arr> 20 30 40
'
#*
lua50 -e '
  a = {}
  mt = {}
  setmetatable(a, mt)
  mtset = function (mtfield)
      mt[mtfield] = function (...) P(mtfield, unpack(arg)) end
    end
  mtset("__add"); b = a + 1
  mtset("__sub"); b = a - 2
  mtset("__mul"); b = a * 3
  mtset("__div"); b = a / 4
  mtset("__pow"); b = a ^ 5
  mtset("__unm"); b =   - a
  mtset("__concat"); b = a .. 6
  mtset("__eq");  b = a == a
  mtset("__lt");  b = a <  9
  mtset("__le");  b = a <= 10
'
#*

  mtset("__concat"); b = a[20]
  mtset("__eq"); b = a[20]
  mtset("__lt"); b = a[20]
  mtset("__le"); b = a[20]
  mtset("__index"); b = a[20]
  mtset("__newindex"); b = a[20]
  b = a[20]



# (find-lua50file "src/")

# (find-lua50file "src/lapi.c" "lua_getmetatable")
# (find-lua50file "src/lobject.h" "typedef struct Table")
# (find-lua50file "src/ltests.c" "static int metatable")
# (find-lua50file "src/ltm.c")
# (find-lua50file "src/lvm.c")
# (find-lua50file "src/lvm.c" "case OP_CALL:")

# (find-lua50file "src/lobject.h" "#define hvalue(o)")



#####
#
# string.find
# 2003mar12
#
#####

# «string.find»  (to ".string.find")
# (find-lua50ref "String Manipulation" "string.find")
# string.find (s, pattern [, init [, plain]])
#   --> begpos endpos captstr1 captstr2 ...
#*
lua50e 'P(string.find("0123456789", "3(45)(67)", 4))	--> 4 8 "45" "67"'
lua50e 'P(string.find("0123456789", "3(45)(67)", 5))	-->'
#*
# «string.gfind»  (to ".string.gfind")
# (find-lua50ref "String Manipulation" "string.gfind")
lua50e 'for w,s in string.gfind("aa!b!!c", "([^!]*)(!?)") do P(w, s) end'
lua50e 'for w,s in string.gfind("aa!b!!c!", "([^!]*)(!?)") do P(w, s) end'
#*



#####
#
# empty captures in patterns
# 2004jan14
#
#####

# «emptycaptures»  (to ".emptycaptures")
# (find-lua50ref "String Manipulation" ". string.find")
# (find-lua50ref "Captures" "the empty capture ()")
# (to "split")
#*
lua50e '
  P(string.find("abbc", "()(b+)()", 1))   --> 2 3  2 "bb" 4
  P(string.find("abbc", "()(b+)()", 2))   --> 2 3  2 "bb" 4
  P(string.find("abbc", "()(b+)()", 3))   --> 3 3  3 "b" 4
  P(string.find("abbc", "()(b+)()", 4))   -->
'
#*
lua50e '
split = function (str)
    local arr, pos = {}, 1
    while 1 do
      local _, __, word, newpos = string.find(str, "^[%s]*([^%s]+)()", pos)
      if newpos then table.insert(arr, word); pos = newpos
      else return arr
      end
    end
  end
PP(split(" abc  de "))
'
#*



#####
#
# 0-based string positions
# 2003mar14
#
#####

# «0-based»  (to ".0-based")
# (find-angg "LUA/lua50init.lua" "0-based")
# (find-lua50ref "string.sub")
# (find-lua50ref "string.find")
# (find-lua50ref "string.byte")
#*
lua50e 'P(string.sub("012345678", 1+2, 7))		--> "23456"'
lua50e 'P(string.find("012345678", "^(23456)", 1+2))	--> 1+2 7 "23456"'
lua50e 'P(string.byte("012345678", 1+4))		--> ?0+4'
#*

* (eepitch-lua)
P(string.sub("012345678", 1+2, 7))             --> "23456"
P(string.find("012345678", "^(23456)", 1+2))   --> 1+2 7 "23456"
P(string.byte("012345678", 1+4))               --> ?0+4







#####
#
# Functions with a variable number of parameters
# 2003mar13
#
#####

# «vararg»  (to ".vararg")
# (find-lua50ref "__call")
# (find-lua50ref "Function Definitions" "arg={5, 8; n=2}")




#####
#
# arg
# 2004sep07
#
#####

# «lua-arg»  (to ".lua-arg")
# (find-man "1 lua")
# (find-luafile "src/lua/lua.c" "\"arg\"")
# (find-zshnode "Process Substitution")
#*
lua50   -e 'PP(arg)'
lua50 =(<<<'PP(arg)') Arg1 Arg2
lua50 =(<<<'print(unpack(arg))') Arg1 Arg2
#*




#####
#
# pack and unpack
# 2007nov26
#
#####

# «pack-and-unpack»  (to ".pack-and-unpack")
# (find-angg "LUA/lua50init.lua" "pack-and-unpack")
# (find-luamanualw3m "#pdf-unpack")
# (find-luamanualw3m "#7.1" "pseudo-argument arg")
# (find-lua51grep "grep -nH -e LUA_COMPAT_VARARG $(cat .files.ch)")
# (find-lua51file "src/ldo.c" "LUA_COMPAT_VARARG")
# (find-lua51file "src/luaconf.h" "LUA_COMPAT_VARARG")
# http://www.lua.org/source/5.1/ldo.c.html#adjust_varargs
# (find-pilw3m "index.html")
# (find-pilw3m "5.2.html" "Variable Number of Arguments" "arg={5, 8; n=2}")

The "arg" table is not discussed much in the reference manual for
lua-5.1... I haven't checked this very thoroughly, but I think that
"arg" is mentioned only at the "Incompatibilities with the Previous
Version" section.

For some reason people don't like the old idea of keeping the size of
an array at its ".n" field, and weird alternatives like having a
different kind of "nil" that is not seen as a "hole" pop up at the
mailing list all the time.

To do: find a link to some recent thread about these "alternative
nils" at the mailing list archive.

  http://lua-users.org/lists/lua-l/

To do: replace the "unpack"s in the init file by "myunpack"s, and the
"return unpack(arg)"s by "return ..."s; also, check for 5.0-isms, and
and for old scripts still lying around that may still be lua-5.0
based.









#####
#
# Some librarish functions
# 2003jan18
#
#####

#*
# «envsubst»  (to ".envsubst")
# (find-angg "LUA/lua50init.lua" "envsubst")
# (find-lua50ref "String Manipulation" "string.gsub")
# (find-lua50ref "Character Class")
# (find-lua50ref "Basic Functions" "ipairs")
# (find-lua50ref "Operating System Facilities" "os.getenv")
#
lua50e 'P(arg[1], string.gsub(arg[1], "%$(%w+)", os.getenv))' '$HOME/LUA/'
lua50e 'setenv_ = {}
        setenv = function (varname, value) setenv_[varname] = value end
        envsubst = function (str)
            return string.gsub(str, "%$([%a_][%w_]*)", function (e)
                return (setenv_ and setenv_[e]) or os.getenv(e) or ""
              end)
          end
        for i,v in ipairs(arg) do P(arg[i], envsubst(arg[i])) end
       ' '$HOME/LUA/' '$BADVAR/foo' '$0w$_Ax0y$//'

#*
# «readfile»  (to ".readfile")
# «writefile»  (to ".writefile")
# (find-angg "LUA/lua50init.lua" "readfile")
# (find-lua50ref "file:read")
# (find-lua50ref "io.open")
# (find-lua50file "src/lib/liolib.c" "io_open")
#
echo hi > /tmp/smallfile
rm -v     /tmp/smallfile-w
lua50e 'readfile = function (fname)
            local f = assert(io.open(fname, "r"))
            local bigstr = f:read("*a")
            f:close()
            return bigstr
          end
        writefile = function (fname, bigstr)
            local f = assert(io.open(fname, "w+"))
            f:write(bigstr)
            f:close()
          end
        P(readfile("/tmp/smallfile"))
	P(writefile("/tmp/smallfile-w", "www\n"))
        P(readfile("/tmp/doesnotexist"))
       '

#*
# «mytostring»  (to ".mytostring")
# (find-angg "LUA/lua50init.lua" "mytostring")
# (find-lua50ref "table.sort")
# (find-lua50ref "tostring")
# (find-lua50ref "string.format")
lua50e '
mysort = function (origtable)
    local tmptable = {}
    for key,val in pairs(origtable) do
      table.insert(tmptable, {key=key, val=val})
    end
    local comp = function (item1, item2)
        local key1, key2 = item1.key, item2.key
        local type1, type2 = type(key1), type(key2)
        if type1==type2 then
          if type1=="number" then return key1 < key2 end
          if type1=="string" then return key1 < key2 end
          return tostring(key1) < tostring(key2)
        else
          return type1<type2
        end
      end
    table.sort(tmptable, comp)
    return tmptable
  end
mytostring = function (v)
    local t = type(v)
    if t=="number" then return tostring(v) end
    if t=="string" then return format("%q", v) end
    if t=="table" then
      local tmptable = mysort(v)
      local bigstring = "{"
      local sep = ""
      for i = 1, table.getn(tmptable) do
        local entry = tmptable[i]
        local keystr, valstr = mytostring(entry.key), mytostring(entry.val)
        bigstring = bigstring..sep..keystr.."="..valstr
        sep = ", "
      end
      return bigstring .. "}"
    end
    return "<"..tostring(v)..">"
  end

print(mytostring({30, "a", [function () end]={true, false}}))
'
#*
# «split»  (to ".split")
# (find-angg "LUA/lua50init.lua" "split")
# (to "emptycaptures")
lua50e '
split = function (str)
    local arr = {}, 1
    string.gsub(str, "([^%s]+)", function (word)
        table.insert(arr, word)
      end)
    return arr
  end
PP(split(" abc  de "))
'
#*




#####
#
# the several flavors of "for"
# 2003feb27
#
#####

# «for»  (to ".for")
# (find-luamanualw3m+ "for")
#*
lua50e 'for i=1,4 do P(i) end'                          ;# 1 2 3 4
lua50e 'for i=5,-2,-2 do P(i) end'                      ;# 5 3 1 -1
lua50e 'for i=2,2 do P(i) end'                          ;# 2
lua50e 'for i=2,0 do P(i) end'                          ;#
lua50e 'for key,val in {4,5,k="K"} do P(key, val) end'  ;# 1 4 / 2 5 / "k" "K"
lua50e 'a={4,5,k="K"}; for i=1,table.getn(a) do P(i, a[i]) end'  ;# 1 4 / 2 5

#*
# (find-lua50ref "next")
#
lua50e 'a={4,5,k="K"}; P(next(a))'
lua50e 'a={4,5,k="K"}; i=nil
        P(next(a,i)); i=next(a,i)
        P(next(a,i)); i=next(a,i)
        P(next(a,i)); i=next(a,i)
        P(next(a,i)); i=next(a,i)
       '
#*
# (find-luamanualw3m+ "for")
# (find-lua50ref "For Statement" "generators")
# (find-lua50ref "For Statement" "generators" "equivalent to")
# (find-lua50ref "Basic Functions" ". ipairs")
# (find-lua50ref "Basic Functions" ". pairs")
#
lua50e 'a={4,5,k="K"}; for key,val in        a  do P(key,val) end'
lua50e 'a={4,5,k="K"}; for key,val in  pairs(a) do P(key,val) end'
lua50e 'a={4,5,k="K"}; for key,val in ipairs(a) do P(key,val) end'
lua50e 'a={4,5,k="K"}; P(ipairs(a))'
lua50e 'a={4,5,k="K"}; f,state,key=ipairs(a); PP(ipairs(a))
        key,val=f(state,key); PP(f,state,key,val)
        key,val=f(state,key); PP(f,state,key,val)
        key,val=f(state,key); PP(f,state,key,val)
'
#*
# (find-lua50ref "table.foreach")
# (find-lua50ref "table.foreachi")
# (find-lua50ref "io.lines")

  * explist is evaluated only once. Its results are an iterator function, a 
    state, and an initial value for the first iterator variable.
  * _f and _s are invisible variables. The names are here for explanatory
    purposes only.
  * The behavior is undefined if you assign to var_1 inside the block.
  * You can use break to exit a for loop.
  * The loop variables var_i are local to the statement; you cannot use their
    values after the for ends. If you need these values, then assign them to
    other variables before breaking or exiting the loop.

#*
# (find-luamanualw3m+ "for" "The generic for statement")
# (find-luamanualw3m+ "for" "iterator function,")
# (find-luamanualw3m+ "next")
# (find-lua50tag "luaB_next")
# (find-lua50tag "lua_next")
# (find-lua50tag "luaH_next")
lua50e '
  PP(ipairs({10, 20}))    --> <function> {1=10,2=20} 0
  itf, state, v = ipairs({10, 20})
  PP(itf 
'

#*
lua50e '
  T = {10,20}
  f, s, a0 = ipairs(T);  PP(f, s, a0)      --> <function> {1=10,2=20} 0
  a1, b1, c1 = f(s, a0); PP(a1, b1, c1)	   --> 1 10 nil
  a2, b2, c2 = f(s, a1); PP(a2, b2, c2)	   --> 2 20 nil
  a3, b3, c3 = f(s, a2); PP(a3, b3, c3)	   --> nil
'
#*
lua50e '
  T = {b="B", a="A"}
  f, s, a0 = pairs(T);  PP(f, s, a0)      --> <function> {"a"="A","b"="B"}
  a1, b1, c1 = f(s, a0); PP(a1, b1, c1)	   --> "a" "A" nil
  a2, b2, c2 = f(s, a1); PP(a2, b2, c2)	   --> "b" "B" nil
  a3, b3, c3 = f(s, a2); PP(a3, b3, c3)	   --> nil
'
#*
# «each2»  (to ".each2")
# (find-angg "LUA/lua50init.lua" "each2")
# (find-pilw3m "7.1.html" "Iterators and Closures")

* (eepitch-lua51)

each2 = function (tbl)
    local i = 1
    return function ()
        if i <= table.getn(tbl) then
          i = i + 2
          return tbl[i - 2], tbl[i - 1]
        end
      end
  end

for a,b in each2(split("aa bb cc dd ee ff")) do print(a, b) end






f, s, a0 = iterator(); PP(f, s, a0)
a1, b1, c1 = f(s, a0); PP(a1, b1, c1)
a2, b2, c2 = f(s, a1); PP(a2, b2, c2)
a3, b3, c3 = f(s, a2); PP(a3, b3, c3)

while true do



#*
       do
         local _f, _s, var_1 = explist
         local var_2, ... , var_n
         while true do
           var_1, ..., var_n = _f(_s, var_1)
           if var_1 == nil then break end
           block
         end
       end



it, st, iv

#*







#####
#
# LUA_PATH and require
# 2003mar16
#
#####

# «require»  (to ".require")
# (find-angg "dednat/dednat3.lua" "luahead" "LUA_PATH")
# (find-lua50ref "require")
# (find-lua50file "src/lib/lbaselib.c" "static int luaB_require")
# (find-lua50file "src/lib/lbaselib.c" "#define LUA_PATH_DEFAULT")
# (find-lua50file "src/lib/lbaselib.c" "getenv(LUA_PATH)")
# (find-lua50file "src/lib/lbaselib.c" "static const char *getpath")
# (find-lua50file "src/lua/lua.c")
#*
echo 'PP(arg)' > /tmp/t.lua
lua50 /tmp/t.lua
cd /tmp/
lua50 t.lua
lua50e 'PP(string.find("/tmp/t.lua", "^(.*)/([^/]*)$"))'
lua50e 'PP(string.find(     "t.lua", "^(.*)/([^/]*)$"))'
#*
cat > /tmp/t.lua <<'%%%'
do local _, __, arg0path = string.find(arg[0], "^(.*)/[^/]*$")
   if arg0path then
     LUA_PATH = (LUA_PATH or getenv("LUA_PATH") or "?;?.lua")..
                ";"..arg0path.."/?"
   end
end
PP(arg)
require "u.lua"
%%%

cat > /tmp/u.lua <<'%%%'
PP(_REQUIREDNAME)
print "u!"
%%%

lua50 /tmp/t.lua
#*

# For, e.g., ".so"s for loadlib:
# scriptpwd = arg0path or "."




#####
#
# "require" and the "package" table in lua5.1
# 2007mar06
#
#####

# «lua5.1-require»  (to ".lua5.1-require")
# http://www.inf.puc-rio.br/~roberto/pil2/chapter15.pdf
# (find-luamanualw3m "#pdf-require")
# (to "compat-5.1")

# (find-compat51file "")
# (find-compat51file "compat-5.1.lua")
# (find-compat51file "compat-5.1.lua" "LUA_PATH")
# (find-lua51file "")
# (find-lua51tag "ll_require")

# «lua5.1-package»  (to ".lua5.1-package")
* (eepitch-lua51)
loadcinvoke()
for k,v in pairs(package) do print(k) end
PP(package.preload)
PP(package.loadlib)
for k,v in pairs(package.loaded) do print(k) end
= package.loaded.cinvoke_lua
PP(package.loaders)
= package.cpath
= package.config
= package.path
= package.seeall






#####
#
# Recompiling .so's for lua4.0 for lua5.0
# 2003mar18
#
#####

# (find-lua50file "include/lauxlib.h" "Compatibility macros")
#*
rm -Rv ~/include/lua50/
mkdir  ~/include/lua50/
cd     ~/include/lua50/
cp -iv $LUA50SRC/include/* .
cp -iv lauxlib.h lauxlib.h.orig
# (find-fline "~/include/lua50/lauxlib.h" 122)
# (find-fline "~/include/lua50/lauxlib.h.orig" 122)
patch -p0 lauxlib.h <<'%%%'
122c122
< /*
---
> #ifdef LAUXLIBCOMPAT
134c134
< */
---
> #endif
%%%

#*




#####
#
# loadlib on lua-5.0
# 2003sep19
#
#####

# «loadlib2»  (to ".loadlib2")
# (find-lua50file "src/lib/loadlib.c")
# (find-lua50file "include/")
#*
cd /tmp/
export LUA50SRC=$HOME/tmp/lua-5.0

cat > so.c <<'%%%'
#include <lauxlib.h>
#include <stdio.h>
static int my_foo(lua_State* L) {
  int n = lua_gettop(L);
  int isnum = lua_isnumber(L, 1);
  int m = lua_tonumber(L, 1);
  printf("Hi hi!\n");
  printf("%d %d %d!\n", n, isnum, m);
  return 0;
}

LUALIB_API int my_init(lua_State *L) {
  lua_register(L, "foo", my_foo);
  return 0;
}
%%%
gcc -g -Wall -shared -I$LUA50SRC/include -o so.so so.c

# (find-lua50ref "Defining C Functions" "lua_register")

cat > loadso.lua <<'%%%'
assert(loadlib("/tmp/so.so", "my_init"))()
foo(22)
%%%

$LUA50SRC/bin/lua /tmp/loadso.lua

#*
# (find-efunction 'eegud-gdb)
# (eegud-gdb t ee-lua50dir "bin/lua")
set args /tmp/loadso.lua
# br main
br loadlib
run
n
n
n
br my_foo
cont

#*





#####
#
# luaL_openlib - for lua_register'ing each function in an array
# 2004jan06
#
#####

# «luaL_openlib»  (to ".luaL_openlib")
# (find-lua50file "src/lib/lbaselib.c" "luaL_reg base_funcs[] =")
# (find-lua50file "src/lib/lbaselib.c" "luaL_openlib(L, NULL, base_funcs, 0)")
# (find-lua50file "include/lauxlib.h" "luaL_openlib")
# (find-lua50tag "luaL_openlib")

# (find-lua50file "src/lib/loadlib.c")
# (find-lua50file "include/")
# (find-lua50ref "Defining C Functions" "#define lua_register(L,n,f)")
# (find-fline "/tmp/luabit/lbitlib.c")
#*
rm -Rv /tmp/dummylib/
mkdir  /tmp/dummylib/
cd     /tmp/dummylib/

cat > dummylib.c <<'%%%'
#include "lauxlib.h"
#include <stdio.h>
static int my_foo(lua_State* L) {
  lua_pushnumber(L, 33);
  lua_pushnumber(L, 333);
  return 2;
}
static const struct luaL_reg bitlib[] = {
{"foo", my_foo},
{NULL,  NULL}
};
LUALIB_API int my_init(lua_State *L) {
  lua_pushvalue(L, LUA_GLOBALSINDEX);
  luaL_openlib(L, NULL, bitlib, 0);
  return 0;
}
%%%

# (find-lua50tag "luaL_openlib")

export LUA50SRC=$HOME/tmp/lua-5.0
gcc -g -Wall -shared -I$LUA50SRC/include -o dummylib.so dummylib.c

cat > testlib.lua <<'%%%'
assert(loadlib("/tmp/dummylib/dummylib.so", "my_init"))()
print(foo(44))
print("ok")
%%%

lua50 /tmp/dummylib/testlib.lua

#*




#####
#
# pio_fontx on lua-5.0
# 2003sep19
#
#####

# «pio_fontx»  (to ".pio_fontx")
# (find-fline "~/vtutil/")
# (find-fline "~/vtutil/Makefile")
# (find-fline "~/vtutil/vtutil.lua" "loadextension")
# (find-fline "~/vtutil/pio_fontx.c")
# (find-fline "$LUA50SRC/")
#*
# (find-fline "~/vtutil/Makefile" "pio_fontx.so:")
cd ~/vtutil/
gcc -Wall -shared -I$HOME/include/lua50 -DLAUXLIBCOMPAT \
  -o /tmp/pio_fontx50.so pio_fontx.c
#*
# (find-lua50file "")
# (find-lua50file "etc/loadlib.c")
lua50e 'assert(loadlib("/tmp/pio_fontx50.so", "pio_fontx_init"))()'
#*
# (find-fline "~/include/lua50/")
#*
cd /tmp/

cat > pio_fontx.c <<'%%%'
#include <lua.h>
#include <lauxlib.h>
#include <sys/ioctl.h>
#include <linux/kd.h>

#include <unistd.h>
#include <string.h>
#include <errno.h>
/* #include <fcntl.h>
 * #include <stdio.h>
 * (find-lua50ref "Querying the Stack")
 * (find-lua50ref "Getting Values from the Stack")
 * (find-lua50file "src/lib/loadlib.c" "luaL_checkstring")
 * (find-lua50file "src/lib/")
 * (find-lua50file "include/")
 * (find-lua50file "include/lua.h")
 * (find-lua50file "include/lauxlib.h" "checkint")
 * (find-vtutilfile "pio_fontx.c")
 */

static int lua_pio_fontx(lua_State* L) {
  struct consolefontdesc cfd;
  int len;
  cfd.chardata = (char *) luaL_checklstring(L, 1, &len);
  cfd.charcount = luaL_checkint(L, 2);
  cfd.charheight = luaL_checkint(L, 3);
  if(ioctl(STDIN_FILENO, PIO_FONTX, &cfd)) {
    lua_pushstring(L, strerror(errno));
    return 1;
  }
  return 0;
}

LUALIB_API int pio_fontx_init(lua_State *L) {
  lua_register(L, "pio_fontx", lua_pio_fontx);
  return 0;
}
%%%
gcc -g -Wall -shared -I$LUA50SRC/include -o pio_fontx.so pio_fontx.c

# (find-lua50ref "Defining C Functions" "lua_register")

cat > loadso.lua <<'%%%'
assert(loadlib("/tmp/pio_fontx.so", "pio_fontx_init"))()
print(pio_fontx)
%%%

$LUA50SRC/bin/lua /tmp/loadso.lua

#*





#####
#
# mailing list archive
# 2003mar01
#
#####

# «mailing-list-archive»  (to ".mailing-list-archive")
# http://www.lua.org/ftp/
#*
cd $S/http/www.lua.org/ftp/
zcat lua-l-archive.gz > /tmp/lua-l-archive
cd /tmp/
laf /tmp/lua-l-archive
#*
mutt -R -f /tmp/lua-l-archive
#*
rm -v /tmp/lua-l-archive
#*
# (find-fline "/tmp/lua-l-archive")





####
#
# Lua's magical hash algorithm
# 2003mar01
#
####

# «hash»  (to ".hash")
# (find-lua50file "src/ltable.c" "then the colliding element")

# (find-shttpw3 "www.citi.umich.edu/projects/linux-scalability/reports/hash-email.html")

i re-read Knuth over dinner last night. unfortunately, he is
discussing hashes where you store data elements right in the hash
table, and can then easily do linear probing [i heard that, you in the
second row]. i can't think of a good way to apply his double hashing
algorithm (algorithm D, p. 528) or Brent's variation (p. 532) to help
improve the hash function without using a multiplicative hash.

cd /tmp/
wget http://www-cs-faculty.stanford.edu/~knuth/err3-1e.ps.gz
gv -page 52 /tmp/err3-1e.ps.gz

Page 526 new paragraph after line 19 29 Nov 1977

E. G. Mallach [Comp. J. 20 (1977), 137-140] has experimented with
refinements of Brent's variation, and further results have been
obtained by Gaston H. Gonnet and J. Ian Munro [SICOMP 8 (1979),
463-478].




#####
#
# how efficient is table.insert(tbl, x, 1)?
# 2003mar13
#
#####

# (find-lua50file "src/ltable.c")
# (find-lua50file "src/lib/ltablib.c" "\nstatic int luaB_tinsert")
# Well, it's not linear time stuff...




#####
#
# io.output
# 2003jul10
#
#####

# «io.output»  (to ".io.output")
# (find-lua50ref "sec5.6" ". io.open (filename [, mode])")
# (find-lua50file "src/lib/liolib.c" "static int io_open")
# (find-node "(libc)Opening Streams")

# (find-lua50ref "sec5.6" ". io.output ([file])")
# (find-lua50ref "sec5.6" ". io.input ([file])")
# (find-lua50file "src/lib/liolib.c" "static int io_output")
# (find-lua50file "src/lib/liolib.c" "static int g_iofile")
# (find-lua50file "src/lib/liolib.c" "static int io_write")
# (find-lua50file "src/lib/liolib.c" "static int g_write")
# (find-lua50file "src/lib/lbaselib.c" "static int luaB_print")
#*
rm -Rv /tmp/io.output/
mkdir  /tmp/io.output/
cd     /tmp/io.output/
lua50e '
  print   ("hi")
  io.write("hi 2\n")
  io.flush()
  io.output("out")	-- same as io.output(assert(io.open("out", "w")))
  print   ("hi 3\n")	-- not redirected; uses fputs(s, stdout)
  io.write("hi 4\n")	-- redirected; uses g_write(L, getiofile(...), ...)
  io.flush()
'
laf
#*

# (find-lua50ref "sec5.6" ". file:write (value1, ...)")
# (find-lua50ref "sec5.6" ". io.write (value1, ...)")





#####
#
# vmmerge5.lua
# 2006aug10
#
#####

# «vmmerge5.lua»  (to ".vmmerge5.lua")
# http://lua-users.org/wiki/VmMerge
# http://lua-users.org/files/wiki_insecure/users/theoddone33/vmmerge5.lua
#*
# Install at ~/bin/ (2006aug10)
{
  echo '#!/usr/bin/env lua50'
  echo '-- (find-es "lua5" "vmmerge5.lua")'
  echo
  cat $S/http/lua-users.org/files/wiki_insecure/users/theoddone33/vmmerge5.lua
}       > ~/bin/vmmerge5.lua
chmod 755 ~/bin/vmmerge5.lua

#*
# Inspect and test:
# (find-fline "~/bin/vmmerge5.lua")
# (find-sh "vmmerge5.lua --file ~/blogme/blogme2.lua")
# (find-sh          "luac -p -l ~/blogme/blogme2.lua")
# (find-fline "~/blogme/blogme2.lua")

<edrx> ok, I'm inspecting the disassembled bytecode for a lua script
       to try to understand how a closure gets the name that is
       displayed on tracebacks...
<Keffo> hmm, wtf is this.. http://www.ubuntu.org/
<Keffo> edrx: Why do you care? :)
<edrx> my only guess at the moment - if the disassembled bytecode
       really shows everything that the bytecode has - is that
       closures are born without names, and "setglobal" notice when
       they are assigning unnamed closures to (named) variables and
       set the name of the closure...
<edrx> but that seems a bit inneficient
<edrx> Keffo: I care because this is one of the two main things that I
       don't understand about Lua and that I have to confess that I
       don't know when I explian Lua to people or give talks about it
       (I gave a few at free software events)

# (find-lua50file "")
# (find-lua50grep "grep -nH -e closure $(cat .files.ch)")
# (find-lua50grep "grep -nH -e LClosure $(cat .files.ch)")
# (find-lua50tag "LClosure")
# (find-lua50grep "grep -nH -e traceback $(cat .files.ch)")
# (find-lua50tag "errorfb")
# (find-lua50file "src/lib/ldblib.c" "\" in function `%s'\", ar.name")

setglobal
closure




#####
#
# vmmerge
# 2003jan08
#
#####

# «vmmerge»  (to ".vmmerge")
# http://lua-users.org/wiki/VmMerge
# http://lua-users.org/files/wiki_insecure/users/ntrout/vmmerge.lua
#*
cat $S/http/lua-users.org/files/wiki_insecure/users/ntrout/vmmerge.lua \
  | tr -d '\r' \
  > ~/LUA/vmmerge5.lua
#*
# (find-fline "~/LUA/vmmerge5.lua")
# (find-fline "~/LUA/vmmerge5.lua" "local cmd = \"luac")
ln -sf ../tmp/lua-5.0-beta/bin/luac ~/bin/luac50
#*
cd ~/LUA/
cat > /tmp/test.lua <<'%%%'
print(1+2)
%%%
lua50 -l ~/tmp/lua-5.0-beta/test/compat.lua vmmerge5.lua \
  --file /tmp/test.lua
#*
cat > /tmp/test.lua <<'%%%'
a = {
  1+2,
  3
}
print(a[2])
%%%
lua -f $S/http/lua-users.org/files/wiki_insecure/users/ntrout/vmmerge.lua \
  --file /tmp/test.lua --fmt merge
#*
echo 'a={}; a(4)' | luac50 -
rm luac.out
cat luac.txt
#*
# (find-lua50file "")
# (find-lua50file "src/lvm.c" "case OP_CALL:")




#####
#
# Suggestions
# 2003mar18
#
#####

# «suggestions»  (to ".suggestions")

Add #ifdefs that activate the compatibily block of lauxlib.h.

Build the array "arg" before running the first "-e".

Allow things like ``while a=f() do ... end'', and maybe something
similar for `if' and `elseif' too.

Power patch: add a way to let the interpreter be a pointer to a
function instead of a fixed function

Power patch: add a keyword that when parsed interrupts the execution
of the interpreter, to let us examine its state

Power patch: create an interpreter that can be interrupted and resumed

Power patch: add a "tfunction" keyword that behaves like "function",
but if a certain global variable ("tfunctionfunction"?) exists it
invokes it just after building the bytecode for the function. For
example, in ``unnamedfunctions["3"] = tfunction return 1+2 end'' we
would have the call ``tfunctionfunction(bytecode, chunk, begpos,
endpos)'', where bytecode is the code for ``function return 1+2 end'',
chunk is the string from where that all came and begpos and endpos are
the positions of the ``tfunction return 1+2 end'' in the string. By
the way: the reason why I want such a beast (tfunction) is that I'd
like to keep a weak table with the source code of the ``user-defined
primitives'' in LForth, that are built from strings in complicated
way.

# (find-lua50file "src/")
# (find-lua50file "src/lparser.c")
# (find-lua50file "src/lcode.c")
# (find-lua50file "src/lib/lbaselib.c" "luaB_loadstring")





#####
#
# tolua-5.0
# 2003dec27
#
#####

# «tolua-5.0»  (to ".tolua-5.0")
# (code-c-d "tolua" "~/usrc/tolua-5.0/")
# (find-toluafile "")
# (find-toluafile "src/tests/")
#*
rm -Rv ~/usrc/tolua-5.0/
cd ~/usrc/
tar -xvzf $S/ftp/ftp.tecgraf.puc-rio.br/pub/users/celes/tolua/tolua-5.0.tar.gz
cd ~/usrc/tolua-5.0/
patch -p0 config <<'%%%'
24c24
< LUA=/home/celes/lua-5.0
---
> LUA=$(HOME)/tmp/lua-5.0
%%%

make |& tee om

# (find-toluafile "Makefile")

#*
cd ~/usrc/tolua-5.0/
make tests |& tee omtests
# Fails and aborts at the "tvariable" test,
# so below we redo it in a more careful way.
# (find-toluafile "omtests")

#*
cd ~/usrc/tolua-5.0/src/tests/
# (find-toluafile "src/tests/Makefile")
make clean klean
rm -fv *.log
rm -fv *.log.FAILED
for i in tmodule tnamespace tclass tconstant tfunction tarray; do
  (setopt -v; make $i && ./$i) |& tee $i.log
done
for i in tvariable tdirective; do
  (setopt -v; make $i && ./$i) |& tee $i.log.FAILED
done
# (find-toluafile "src/tests/")

#*
eev-cd tolua
lynx doc/tolua-3.2.html

#*




#####
#
# tolua-5.1b
# 2007aug08
#
#####

# «tolua-5.1»  (to ".tolua-5.1")
# http://www.tecgraf.puc-rio.br/~celes/tolua/
# http://www.tecgraf.puc-rio.br/~celes/tolua/tolua-3.2.html
# ftp://ftp.tecgraf.puc-rio.br/pub/users/celes/tolua/tolua-5.1b.tar.gz
#*
rm -Rv ~/usrc/tolua-5.1b/
tar -C ~/usrc/ -xvzf \
  $S/ftp/ftp.tecgraf.puc-rio.br/pub/users/celes/tolua/tolua-5.1b.tar.gz
cd     ~/usrc/tolua-5.1b/

#*
# (code-c-d "tolua" "~/usrc/tolua-5.1b/")
# (find-toluafile "")
# (find-toluash "find * | sort")
# (find-toluafile "src/bin/lua/")
# (find-toluafile "src/tests/")





#####
#
# tagging lua programs with etags
# 2003dec30
#
#####

# «etags»  (to ".etags")
# (find-man "1 etags" "Tag the DEFVAR")
# (find-man "1 etags" "regexps are cumulative")
# (find-man "1 etags" "/\\1/")
# (find-man "1 etags" "regex files")
# (find-progoutput "etags --help")
#*
cd ~/dednat4/
etags --lang=none --regex="/[a-zA-Z_0-9.]+[ \t]+=/" *.lua
mv -v TAGS TAGS0
etags --lang=none --regex='/\([a-zA-Z_0-9.]+\)[ \t]+=/\1/' *.lua
mv -v TAGS TAGS1

cat > /tmp/regex-lua-etags <<'%%%'
/\([a-zA-Z_0-9.]+\)[ \t]+=/\1/
%%%
etags --lang=none --regex=@/tmp/regex-lua-etags *.lua
mv -v TAGS TAGS2

#*
cat > /tmp/regex-lua-etags <<'%%%'
  (find-es "lua5" "etags")
  (find-man "1 etags" "/\\1/")
  (find-man "1 etags" "regex files")
  (find-anchor "Makefile" "TAGS")

  Regexps for tagging lua files:

/\([a-zA-Z_0-9.]+\)[ \t]+=/\1/
/\([a-zA-Z_0-9.]+\),/\1/
/forths\["\([^ ]*\)"\] =/\1/
%%%

#*
# (find-fline "~/dednat4/TAGS0")
# (find-fline "~/dednat4/TAGS1")
# (find-fline "~/dednat4/TAGS2")

# Note: this only works because I always define functions with a
# syntax like this...
# myfunction = function (arg1, arg2)
#     ...
#   end




#####
#
# readline support
# 2004jan04
#
#####

# «readline»  (to ".readline")
# (find-lua50file "om" "-DUSE_READLINE")
# (find-lua50file "om" "-DLUA_USERCONFIG=")
# (find-lua50file "Makefile" "all clean co klean:" "cd src/lua; $(MAKE) $@")
# (find-lua50file "src/lua/Makefile" "EXTRA_DEFS= $(USERCONF)")
# (find-lua50file "src/lua/Makefile" "include $(LUA)/config")
# (find-lua50file "config"  "#USERCONF=-DLUA_USERCONFIG=")
# (find-lua50file "config" "\nUSERCONF=-DLUA_USERCONFIG=" "saconfig.c")
# (find-lua50file "src/lua/lua.c" "#include LUA_USERCONFIG")
# (find-lua50file "etc/saconfig.c" "#ifdef USE_READLINE")

# (find-node "(make)Catalogue of Rules" "$(CC) -c $(CPPFLAGS) $(CFLAGS)")
# (find-lua50file "config" "CFLAGS= $(MYCFLAGS) $(WARN) $(INCS) $(DEFS)")
# (find-lua50file "config" "DEFS= $(NUMBER) $(EXTRA_DEFS)")

# (find-lua50file "etc/saconfig.c" "static int myreadline")
# (find-node "(readline)Basic Behavior" "char *readline (const char *PROMPT)")
# (find-node "(readline)Basic Behavior" "add_history (line)")
# (find-node "(history)Top")

#*
eev-cd lua50
grep USERCONF $(find * -type f); echo
grep EXTRA_DEFS $(find * -type f); echo
grep lua_readline $(find * -type f); echo
grep lua_saveline $(find * -type f); echo

#*




####
#
# stringtolines - split a string at "\n"s
# 2004jan11
#
####

# «stringtolines»  (to ".stringtolines")
# (find-lua50ref "String Manipulation" ". string.gsub")
#*
lua50e '
stringtolines = function (str)
    local lines = {}
    local rest = string.gsub (str, "([^\n]*)\n", function (line)
        table.insert(lines, line)
      end)
    if rest ~= "" then table.insert(lines, rest) end
    return lines
  end
PP(stringtolines("line1\nline2\nline3"))
PP(stringtolines("line1\nline2\n"))
'
#*





#####
#
# the posix library on lua-5.1 (luaposix-5.1.4)
# 2008jul18
#
#####

# «luaposix»  (to ".luaposix")
# http://luaforge.net/frs/download.php/3572/luaposix-5.1.4.tar.gz
#*
rm -Rv ~/usrc/luaposix-5.1.4/
tar -C ~/usrc/ -xvzf \
  $S/http/luaforge.net/frs/download.php/3572/luaposix-5.1.4.tar.gz
cd     ~/usrc/luaposix-5.1.4/

make LUAINC=

#*
# (code-c-d "lposix" "~/usrc/luaposix-5.1.4/")
# (find-lposixfile "")




#####
#
# the posix library on lua-5.1
# 2007may14
#
#####

# «posix-lua51»  (to ".posix-lua51")
# (find-angg "LUA/lua50init.lua" "loadposix")
# (code-c-d "lposix" "~/usrc/posix/")
# (find-lposixfile "")
# (find-lposixfile "omxx")
# (find-lposixfile "Makefile")
# (find-lposixfile "posix.lua" "LUA_SOPATH")
# http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/index.html#lposix
# http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/5.0/lposix.tar.gz
# http://lua-users.org/lists/lua-l/2007-05/msg00087.html
#*
rm -Rv ~/usrc/posix/
tar -C ~/usrc/ -xvzf \
  $S/http/www.tecgraf.puc-rio.br/~lhf/ftp/lua/5.0/lposix.tar.gz
cd     ~/usrc/posix/

# Patch to make it run on Lua-5.1:
# http://lua-users.org/lists/lua-l/2007-05/msg00087.html
patch -p0 lposix.c <<'%%%'
67,68c67,69
< 		int j=luaL_findstring(luaL_checkstring(L, i), S);
< 		if (j==-1) luaL_argerror(L, i, "unknown selector");
---
> 		/* int j=luaL_findstring(luaL_checkstring(L, i), S);   */
> 		/* if (j==-1) luaL_argerror(L, i, "unknown selector"); */
> 		int j=luaL_checkoption(L, i, NULL, S);	    /* lua 5.1 */
%%%

etags *.c

cp -iv posix.lua posix.lua.orig
cat > posix.lua <<'%%%'
assert(package.loadlib("./lposix.so", "luaopen_posix"))()
%%%

cp -v tree.lua tree.lua.orig
patch -p0 tree.lua <<'%%%'
22c22
<     for i, name in files do
---
>     for i, name in ipairs(files) do
55c55
< directory = (arg.n > 0) and arg[1] or '.'
---
> directory = (table.getn(arg) > 0) and arg[1] or '.'
%%%

cd ~/usrc/posix/
make LUAINC=$LUA51SRC/src lposix.so  |& tee om
make LUABIN=$LUA51SRC/src tree       |& tee omtree
make LUABIN=$LUA51SRC/src x          |& tee omx
make LUABIN=$LUA51SRC/src xx         |& tee omxx

#*

* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
loadposix()
PP(posix)

* (defun eepitch-lua51posix () (interactive) (eepitch-at-dir-comint "~/usrc/posix/" "lua51posix" "lua51"))
* (eepitch-lua51posix)
dofile "posix.lua"
files = posix.dir(".")
= files
PP(files)
PP(posix)


-- (find-lposixfile "posix.lua")
-- (find-lposixfile "tree.lua")

#*
# «posix-install»  (to ".posix-install")
# Obsolete - now (lua-5.1) I load the ".so" from ~/usrc/posix/".
cd ~/usrc/posix/
cp -v ~/usrc/posix/lposix.so ~/.lua50/
lua50 -e 'load_posix(); PP(posix)'

#*
# «load_posix»  (to ".load_posix")
# (find-angg "LUA/lua50init.lua" "load_posix")
# (find-lposixfile "posix.lua" "function so(x)")
# (find-lposixfile "")








#####
#
# posix functions (new; the old block is below)
# 2004jan14
#
#####

# «posix»      (to ".posix")
# «posix-new»  (to ".posix-new")
# (code-c-d "lposix" "~/usrc/posix/")
# (find-lposixfile "")
# (find-lposixfile "oxx")
# (find-lposixfile "Makefile")
# (find-lposixfile "posix.lua" "LUA_SOPATH")
# http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/5.0/lposix.tar.gz
# Patch to make it run on Lua-5.1:
# http://lua-users.org/lists/lua-l/2007-05/msg00087.html
#*
rm -Rv ~/usrc/posix/
cd     ~/usrc/
tar -xvzf $S/http/www.tecgraf.puc-rio.br/~lhf/ftp/lua/5.0/lposix.tar.gz
cd ~/usrc/posix/

etags *.c

# (find-angg ".zshrc" "lua" "LUASRC")
# maybe I should use $LUASRC/bin/lua as the binary...
export LUASRC=$HOME/usrc/lua-5.0.2

make LUA=$LUASRC lposix.so  |& tee om
make LUA=$LUASRC tree       |& tee omtree
make LUA=$LUASRC x          |& tee omx
make LUA=$LUASRC xx         |& tee omxx |& tee oxx

#*
# «posix-install»  (to ".posix-install")
cd ~/usrc/posix/
cp -v ~/usrc/posix/lposix.so ~/.lua50/
lua50 -e 'load_posix(); PP(posix)'

#*
# «load_posix»  (to ".load_posix")
# (find-angg "LUA/lua50init.lua" "load_posix")
# (find-lposixfile "posix.lua" "function so(x)")
# (find-lposixfile "")







#####
#
# posix functions (old; the new block is above)
# 2004jan14
#
#####

# «posix-old»  (to ".posix-old")
# (code-c-d "lposix" "~/usrc/posix/")
# (find-lposixfile "")
# (find-lposixfile "oxx")
# http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/lposix.tar.gz
#*
# 2005jan01: trying to use sarge's lua package

rm -Rv ~/usrc/posix/
cd     ~/usrc/
tar -xvzf $S/http/www.tecgraf.puc-rio.br/~lhf/ftp/lua/lposix.tar.gz
cd ~/usrc/posix/

# (find-lposixfile "Makefile")
# (find-lposixfile "posix.lua" "LUA_SOPATH")
make LUAINC=/usr/include/lua50  lposix.so
make LUABIN=/usr/bin            tree

# oops! it segfauls...

#*
# Build with an upstream lua-5.0.2 instead.

rm -Rv ~/usrc/posix/
cd     ~/usrc/
tar -xvzf $S/http/www.tecgraf.puc-rio.br/~lhf/ftp/lua/lposix.tar.gz
cd ~/usrc/posix/

# (find-angg ".zshrc" "lua" "LUASRC")
export LUASRC=$HOME/usrc/lua-5.0.2

# make LUA=$HOME/tmp/lua-5.0 |& tee om
make LUA=$LUASRC lposix.so
make LUA=$LUASRC tree
make LUA=$LUASRC x
make LUA=$LUASRC xx | tee oxx

#*
# (find-angg ".zshrc")
# (find-lposixfile "posix.lua")
cd ~/usrc/posix/
cp -v lposix.so ~/.lua50/

#*
lua50 -e '
HOME = os.getenv("HOME")
assert(loadlib(HOME.."/.lua50/lposix.so", "luaopen_posix"))()
f = posix.files()
while 1 do
  fname = f()
  if fname == nil then break end
  print(fname)
end
'

#*
# (find-lposixfile "lposix.c" "static int Pstat")
# (find-k24file "Documentation/devices.txt" "hda")
# (find-k24file "Documentation/devices.txt" "hdc")
lua50 -e '
  HOME = os.getenv("HOME")
  assert(loadlib(HOME.."/lib/lposix.so", "luaopen_posix"))()
  fname = "/tmp/o"
  s = posix.stat(fname)
  PP(s)
  dev = s.dev
  devmod64 = math.mod(dev, 64)
  hdname = {}
  hdname[256*3+0]   = "hda"
  hdname[256*3+64]  = "hdb"
  hdname[256*22+0]  = "hdc"
  hdname[256*22+64] = "hdd"
  print(fname, hdname[dev-devmod64], devmod64)
'
#*
lua50 -e '
  LIBDIR = os.getenv("HOME").."/lib/lua5"
  assert(loadlib(LIBDIR.."/lposix.so", "luaopen_posix"))()
  fname = "/home/edrx/o"
  s = posix.stat(fname)
  PP(s)
  dev = s.dev; low = math.mod(dev, 256); hi = (dev-low)/256
  str = string.format(" %d,%4d", hi, low)
  print(str)
  command = format("cd /dev/; ls -l hd* | grep \"%s\"", str)
  print(command)
  os.execute(command, str)
'
#*





#####
#
# pushglobals and poglobals
# 2004feb21
#
#####

# «pushglobals-poglobals»  (to ".pushglobals-poglobals")
#*
lua50e '
tinsert = table.insert
tremove = table.remove
getn    = table.getn
_vars = {n=0}
pushglobals = function (...)
    for i=1,getn(arg) do
      local varname = arg[i]
      tinsert(_vars, {varname, _G[varname]})
    end
  end
popglobals = function (...)
    for i=getn(arg),1,-1 do
      local varname, pair = arg[i], tremove(_vars)
      if varname ~= pair[1] then
        error("tried to pop "..varname.." but _vars had "..pair[1].." on top")
      end
      _G[varname] = pair[2]
    end
  end

foo = "FOO"
bar = "BAR"
pushglobals("foo", "bar")
foo = "Foo"
bar = "Bar"
popglobals("foo", "bar")
P(foo, bar)
'
#*




#####
#
# string.gsub with multiple alternatives
# 2004feb21
#
#####

# «gsub-with-alternatives»  (to ".gsub-with-alternatives")
# (find-lua50ref "string.gsub")

# (find-luafile "src/lib/lstrlib.c")
# (find-luafile "src/lib/lstrlib.c" "static int str_gsub")
# (find-luafile "src/lib/lstrlib.c" "char *match " "char *match ")

Idea: string.gsub(s, pat1, repl1,
                     pat2, repl2,
                     pat3, repl3, ...)

would, at each char, test the string "s" against pat1, pat2, ...; the
first one to match would be replaced - and, as usual, each repln is
either a string or a function.

That would be a cheap way to implement a simple form of "|".



####
#
# C calling lua
# 2004feb25
#
####

# «C-calls-lua»  (to ".C-calls-lua")
#*
rm -Rv ~/tmp/ccallslua/
mkdir  ~/tmp/ccallslua/
cd     ~/tmp/ccallslua/
cat > script.lua <<'%%%'
luafunction = function (a, b)
    return "<"..a.." "..b..">"
  end
%%%

# (find-lua50ref "Getting Values from the Stack")
# (find-lua50ref "The Stack and Indices" "negative index")
# (find-lua50ref "Pushing Values onto the Stack")
# (find-lua50ref "Calling Functions" "a = f(\"how\", t.x, 14)")
# (find-lua50ref "Manipulating Tables")
# (find-luatag "luaopen_base")
# (find-luatag "openstdlibs")
# (find-luatag "lualibs")
# (find-lua50ref "Standard Libraries" "luaopen_string")

cat > callit.c <<'%%%'
#include <stdio.h>
#include <stdlib.h>
#include <lua.h>
#include <lauxlib.h>

void PP(lua_State *L, int index) {
  lua_pushstring(L, "PP");
  lua_gettable(L, LUA_GLOBALSINDEX);
  lua_pushvalue(L, index<0?index-1:index);
  lua_call(L, 1, 0);
}

int main(int argc, char **argv) {
  lua_State *L;
  char *rslt;
  L = lua_open();
  luaopen_base(L);                   /* pushes 1 thing */
  luaopen_string(L);                 /* pushes 1 thing */
  luaopen_table(L);                  /* pushes 1 thing */
  luaopen_io(L);                     /* pushes 3 things */
  lua_pop(L, 6);                     /* removes these 1+1+1+3 things */
  lua_dofile(L, "/home/edrx/LUA/lua50init.lua"); /* for "PP" and debug stuff */
  lua_dofile(L, "script.lua");
  lua_pushstring(L, "luafunction");  /* function name: "luafunction" */
  lua_gettable(L, LUA_GLOBALSINDEX); /*   -> function:  luafunction  */
  lua_pushstring(L, "foo");          /* argument 1: "foo" */
  lua_pushnumber(L, 45);             /* argument 2: 45 */
  lua_call(L, 2, 1);                 /* call with 2 args and 1 result */
  rslt = lua_tostring(L, -1);        /* rslt = "<foo 45>" */
  lua_pop(L, 1);                     /* remove rslt */
  printf("rslt = \"%s\"\n", rslt);
  lua_close(L);
}
%%%

# (find-node "(gcc-300)Link Options")
# -L$HOME/usrc/lua-5.0.2/lib -llualib -llua

gcc -g -o callit callit.c -ldl -lm \
    -I$HOME/usrc/lua-5.0.2/include \
    ~/usrc/lua-5.0.2/lib/liblua.a \
    ~/usrc/lua-5.0.2/lib/liblualib.a \

./callit

#*
# (eegud-gdb t "/home/edrx/tmp/ccallslua/" "callit")
# (find-node "(gdb)Calling")
# (find-node "(gdb)Define")

define depth
  p lua_gettop(L)
end
define PP
  call PP(L, $arg0)
end

br main
run

#*





#####
#
# inspecting the Lua stack
# 2004sep02
#
#####

# «luastackPP»  (to ".luastackPP")
#*
rm -Rv ~/tmp/luastackPP/
mkdir  ~/tmp/luastackPP/
cd     ~/tmp/luastackPP/
cat > luastackPP.c <<'%%%'
#include <stdio.h>
#include <stdlib.h>
#include <lua.h>
#include <lauxlib.h>
void PP(lua_State *L, int index) {
  lua_pushstring(L, "PP");
  lua_gettable(L, LUA_GLOBALSINDEX);
  lua_pushvalue(L, index<0?index-1:index);
  lua_call(L, 1, 0);
}
LUALIB_API int luastackPP_init(lua_State *L) {
  /* nothing to do on the Lua side; we're only adding C functions */
  return 0;
}
%%%
gcc -g -Wall -shared -I$LUASRC/include -o luastackPP.so luastackPP.c
cp -v ~/tmp/luastackPP/luastackPP.so \
            ~/lib/lua5/luastackPP.so

#*
cat > /tmp/testPP.lua <<'%%%'
  LIBDIR = os.getenv("HOME").."/lib/lua5"
  assert(loadlib(LIBDIR.."/luastackPP.so", "luastackPP_init"))()
  math.sin(0)
  -- print(1, 2+"3", string.sub)
  print("aa", "bb", "cc", "dd", "ee")
%%%
cat /tmp/testPP.lua        >  /tmp/testPP.lst
luac -p -l /tmp/testPP.lua >> /tmp/testPP.lst
lua50 /tmp/testPP.lua

#*
# (let ((eebd-function-is nil)) (eegud-gdb t ee-luadir "bin/lua"))
# (find-fline "/tmp/testPP.lst")
# (find-node "(gdb)Calling")
# (find-node "(gdb)Define")

define depth
  p lua_gettop(L)
end
define PP
  call PP(L, $arg0)
end

set args /tmp/testPP.lua
# br main
br math_sin
run

#*



#*

# (find-fline "/tmp/luabit/lbitlib.c")






#####
#
# composes (for compose.el)
# 2004jan14
#
#####

# «composes»  (to ".composes")
# (find-angg "compose.el")
# (find-angg "compose-new.el")
#*
cat > /tmp/prc.lua <<'%%%'
quote = function (str)
    return string.gsub(str, "([\\\"])", "\\%1")
  end
composes = function (str)
    local compstr = ""
    for _,w in split(str) do
      if string.len(w) == 1 then 
        compstr = compstr .. " ?" .. quote(w)
      else
        compstr = compstr .. "  \"" .. quote(w) .."\""
      end
    end
    return compstr
  end
prc = function (str)
    print(composes(str))
  end

prc " `A À  `E È  `I Ì  `O Ò  `U Ù"
prc " `a à  `e è  `i ì  `o ò  `u ù"
prc " 'A Á  'E É  'I Í  'O Ó  'U Ú"
prc " 'a á  'e é  'i í  'o ó  'u ú"
prc " ^A Â  ^E Ê  ^I Î  ^O Ô  ^U Û"
prc " ^a â  ^e ê  ^i î  ^o ô  ^u û"
prc " ~A Ã              ~O Õ      "
prc " ~a ã              ~o õ      "
prc "\"A Ä \"E Ë \"I Ï \"O Ö \"U Ü"
prc "\"a ä \"e ë \"i ï \"o ö \"u ü"
prc " 'C Ç  CC Ç  ~N Ñ"
prc " 'c ç  cc ç  ~n ñ"
prc " _a ª  _o º  AE Æ  ae æ      "
prc " !! ¡  ?? ¿  SS §  << «  >> »"
prc " 00 °  11 ¹  22 ²  33 ³      "
prc " 14 ¼  12 ½  34 ¾            "
prc " +- ±  :- ÷  cd ·  xx ×      "
%%%
lua50 /tmp/prc.lua | tee ~/o
#*

(defvar composes-accents '(
   "`A" ?À   "`E" ?È   "`I" ?Ì   "`O" ?Ò   "`U" ?Ù
   "`a" ?à   "`e" ?è   "`i" ?ì   "`o" ?ò   "`u" ?ù
   "'A" ?Á   "'E" ?É   "'I" ?Í   "'O" ?Ó   "'U" ?Ú
   "'a" ?á   "'e" ?é   "'i" ?í   "'o" ?ó   "'u" ?ú
   "^A" ?   "^E" ?Ê   "^I" ?Î   "^O" ?Ô   "^U" ?Û
   "^a" ?â   "^e" ?ê   "^i" ?î   "^o" ?ô   "^u" ?û
   "~A" ?Ã                       "~O" ?Õ
   "~a" ?ã                       "~o" ?õ
  "\"A" ?Ä  "\"E" ?Ë  "\"I" ?Ï  "\"O" ?Ö  "\"U" ?Ü
  "\"a" ?ä  "\"e" ?ë  "\"i" ?ï  "\"o" ?ö  "\"u" ?ü
   "'C" ?Ç   "CC" ?Ç   "~N" ?Ñ
   "'c" ?ç   "cc" ?ç   "~n" ?ñ
))
(defvar composes-otheriso '(
   "_a" ?ª   "_o" ?º   "AE" ?Æ   "ae" ?æ
   "!!" ?¡   "??" ?¿   "SS" ?§   "<<" ?«   ">>" ?»
   "00" ?°   "11" ?¹   "22" ?²   "33" ?³
   "14" ?¼   "12" ?½   "34" ?¾
   "+-" ?±   ":-" ?÷   "cd" ?·   "xx" ?×
))
(defvar composes-globalmath nil)
(defvar composes-localmath nil)
(defvar composes-all nil)
(defun composes-update ()
  (setq composes-all (append composes-localmath composes-globalmath
			     composes-accents composes-otheriso)))
(composes-update)


# (find-fline "~/vtutil4/vtfontlib.lua")




####
#
# stdlib (from the CVS)
# 2004mar01
#
####

# «stdlib»  (to ".stdlib")
# See <http://lua-users.org/wiki/StandardLibraries>
# (code-c-d "luastdlib" "~/usrc/lua-users/stdlib/")
# (code-c-d "luastd" "~/usrc/lua-users/stdlib/modules/")
# (find-luastdlibfile "")
# (find-luastdlibfile "README")
# (find-luastdlibfile "utils/ldoc")
# (find-luastdfile "")
# (find-luastdfile "std.parser.lua")
# (find-luastdfile "std.object.lua")
# (find-luastdfile "std.io.io.lua")
# (find-luastdfile "std.io.env.lua")
# (find-luastdfile "std.rex.lua")
# (find-luastdfile "std.string.regex.lua")
# (find-luastdfile "std.string.string.lua")
#*
rm -Rv ~/usrc/lua-users/
mkdir  ~/usrc/lua-users/
cd     ~/usrc/lua-users/
cvs     -d:pserver:anonymous@cvs.lua-users.sourceforge.net:/cvsroot/lua-users login 
cvs -z3 -d:pserver:anonymous@cvs.lua-users.sourceforge.net:/cvsroot/lua-users co stdlib

#*
# http://optusnet.dl.sourceforge.net/sourceforge/lua-users/luastdlib-2.zip
rm -Rv   ~/usrc/lua-users/
mkdir -p ~/usrc/lua-users/stdlib/
cd       ~/usrc/lua-users/stdlib/
unzip $S/http/optusnet.dl.sourceforge.net/sourceforge/lua-users/luastdlib-2.zip

cd ~/usrc/lua-users/stdlib/modules/
tar -xvzf ~/tmp/rrt.tgz

cd ~/usrc/lua-users/stdlib/modules/
# lua50 clue
lua50 -e 'bit={}' std.lua

#*
# New way (untested), from a message by Richard Simes at lua-l, 2006sep18:
# cvs -d :pserver:anonymous@luaforge.net:/cvsroot/stdlib login
# (press enter when prompted for a password)
# cvs -d :pserver:anonymous@luaforge.net:/cvsroot/stdlib checkout stdlib




# «stdlib2»  (to ".stdlib2")

# http://luaforge.net/frs/download.php/2086/stdlib-2.tar.gz
#*
rm -Rv ~/usrc/lua-users/
mkdir  ~/usrc/lua-users/
cd     ~/usrc/lua-users/
tar -C ~/usrc/lua-users/ -xvzf \
  $S/http/luaforge.net/frs/download.php/2086/stdlib-2.tar.gz

#*
# See <http://lua-users.org/wiki/StandardLibraries>
# (code-c-d "luastdlib" "~/usrc/lua-users/stdlib/")
# (code-c-d "luastd"    "~/usrc/lua-users/stdlib/modules/")
# (find-luastdlibfile "")
# (find-luastdlibfile "README")
# (find-luastdlibfile "utils/ldoc")
# (find-luastdfile "")





#####
#
# rici lake's parser
# 2004aug02
#
#####

# «ricilake-parser»  (to ".ricilake-parser")
# http://lua-users.org/wiki/RiciLake
# http://lua-users.org/files/wiki_insecure/users/rici/blex.lua
# http://lua-users.org/files/wiki_insecure/users/rici/parser.tgz
# (code-c-d "riciparser" "~/usrc/parser/")
# (find-riciparserfile "")
# (find-riciparserfile "preprocess.lua")
# (find-riciparserfile "tnt.lua")
#*
rm -Rv ~/usrc/parser/
tar -C ~/usrc/ \
  -xvzf $S/http/lua-users.org/files/wiki_insecure/users/rici/parser.tgz
cd ~/usrc/parser/
rm -v *.html
rm -v lparse.lua

#*
cd ~/usrc/parser/
lua50 preprocess.lua < lparse.lpp > lparse.lua
for i in *; do
  echo $i
  lua50 tnt.lua $i
done

#*





#####
#
# libluaRRT
# 2004aug30
#
#####

# «reuben-thomas-libs»  (to ".reuben-thomas-libs")
# http://www.mupsych.org/~rrt/Lua
# http://rrt.sc3d.org/download/software/lualibs.zip
# (code-c-d "rrtlibs" "~/usrc/lualibs/")
# (find-rrtlibsfile "")
# (find-rrtlibsfile "README")
# (find-rrtlibsfile "Makefile")
#*
rm -Rv ~/usrc/lualibs/
mkdir  ~/usrc/lualibs/
cd     ~/usrc/
unzip -a $S/http/rrt.sc3d.org/download/software/lualibs.zip
cd     ~/usrc/lualibs/

# (find-rrtlibsfile "lrexlib.c" "#include <pcre/pcre.h>")
# (find-vldifile "libpcre3-dev.list")
cp -v  lrexlib.c lrexlib.c.orig
patch -p0 lrexlib.c <<'%%%'
178c178
< #include <pcre/pcre.h>
---
> #include <pcre.h>
%%%

# (find-node "(make)Catalogue of Rules" "Compiling C programs")
# (find-gccnode "Directory Options")
make CFLAGS="-I$LUASRC/include  -W -Wall -DWITH_POSIX -DWITH_PCRE" so

#*
# (find-rrtlibsfile "")
# (find-rrtlibsfile "README" "luaopen_bit")
# (find-rrtlibsfile "README" "luaopen_rex")
cd  ~/usrc/lualibs/
lua50 -e '
  assert(loadlib("./libluaRRT.so", "luaopen_bit"))()
  assert(loadlib("./libluaRRT.so", "luaopen_rex"))()
  PP(bit)
  PP(rex)
'

#*
mkdir ~/lib/lua5/
cd ~/usrc/lualibs/
cp -av libluaRRT.so libluaRRT.so.0 ~/lib/lua5/
cd  ~/lib/lua5/

#*

# (find-status   "libpcre3-dev")
# (find-udfile   "libpcre3-dev/")

# (find-gccnode "Option Summary" "-fPIC")





envsubst = function (str)
     return string.gsub(str, "%$([%a_][%w_]*)", function (e)
         return getenv(e) or ""
       end)
   end




# (find-lua50ref "The Reflexive Debug Interface")
# (find-lua50ref "The Reflexive Debug Interface" ". debug.debug")
# (find-lua50ref "Basic Functions" ". xpcall")
# (find-lua50file "src/lib/ldblib.c")


# (find-lua50file "")



# (find-tkluafile "config")
# (find-tkluafile "src/bin/Makefile")

# (find-toluafile "")

# (find-tkluafile "patches/tolua-4.0a-patch")
# (find-toluafile "src/lib/tolua_gp.c" "tolua_getvalue")

# (find-fline "/usr/src/tklua/")
# (find-tkluaw3 "doc/")
# (find-tkluafile "test/")
# (find-tkluafile "")
# (find-tkluafile "src/bin/")
# (find-tkluafile "src/lib/")

# (find-status "tk8.3-dev")
# (find-vldifile "tk8.3-dev.list")
# (find-fline "/usr/doc/tk8.3-dev/")

# (load-library "~/LUA/lua.el")
# (find-fline "/usr/doc/lua/examples/")

http://toms.net/tomsrtbt-sources/part2/rb/2/bin/




#####
#
# 
# 2005oct27
#
#####

# CGILUALIBPATH=
# (find-luamanualw3m+ "require")
# LUAPATH="?;?.lua;$HOME/usrc/cgilua-5.0/?"



#####
#
# cgilua and compat-5.1
# 2004jul31
#
#####

#*
# «compat-5.1»  (to ".compat-5.1")
# http://luaforge.net/frs/download.php/952/compat-5.1r4.tar.gz
# http://www.keplerproject.org/compat/manual.html#configuration
# (code-c-d "compat51" "~/usrc/compat-5.1r4/")
# (find-compat51file "")
# (find-compat51file "compat-5.1.lua" "LUA_PATH")
# (find-compat51file "compat-5.1.lua" "LUA_CPATH")
#
rm -Rv ~/usrc/compat-5.1r4/
tar -C ~/usrc/ -xvzf \
  $S/http/luaforge.net/frs/download.php/952/compat-5.1r4.tar.gz
cd     ~/usrc/compat-5.1r4/
gcc -g -Wall -shared -I$LUASRC/include -o compat-5.1.so compat-5.1.c

mkdir ~/usrc/cgilua-5.0/
cp -v compat-5.1.so compat-5.1.lua ~/usrc/cgilua-5.0/

#*
# «cgilua»  (to ".cgilua")
# http://www.keplerproject.org/cgilua/
# http://luaforge.net/frs/download.php/971/cgilua-5.0.tar.gz
# (code-c-d "cgilua" "~/usrc/cgilua-5.0/")
# (find-cgiluafile "")
# (find-cgiluafile "doc/")
# (find-cgiluaw3m  "doc/us/manual.html#installation")
# (find-cgiluafile "src/cgilua/")
# (find-cgiluafile "src/cgilua/Makefile")
# (find-cgiluafile "tests/")
# (find-cgiluafile "tests/Makefile")

rm -Rv ~/usrc/cgilua-5.0/
tar -C ~/usrc/ -xvzf \
  $S/http/luaforge.net/frs/download.php/971/cgilua-5.0.tar.gz
cd     ~/usrc/cgilua-5.0/

cd     ~/usrc/compat-5.1r4/
cp -v compat-5.1.so compat-5.1.lua          ~/usrc/cgilua-5.0/bin/
cd     ~/usrc/cgilua-5.0/

cd     ~/usrc/cgilua-5.0/src/cgilua/
cp -v cgilua.lua cookies.lua lp.lua         ~/usrc/cgilua-5.0/bin/
cp -v post.lua readuntil.lua                ~/usrc/cgilua-5.0/bin/
cp -v serialize.lua session.lua urlcode.lua ~/usrc/cgilua-5.0/bin/
cp -v config.lua                            ~/usrc/cgilua-5.0/bin/
cd     ~/usrc/cgilua-5.0/

#*
# Not ready...
# (find-cgiluafile "omm")

# (find-cgiluafile "src/cgilua/")
# (find-cgiluafile "tests/")







#####
#
# apresentação super-rápida
# 2004sep02
#
#####

# «quick-presentation»  (to ".quick-presentation")
#*
# Tipos de dados básicos
lua50 -e '
  print(1,     type(1))
  print(1.0,   type(1.0))
  print("abc", type("abc"))
  print(nil,   type(nil))
  print(true,  type(true))
  print(false, type(false))
  print(print, type(print))
  print({2,3,5}, type({}))
'
#*
# Funções são valores
lua50 -e '
  function square(a)     return a*a  end
  square = function (a)  return a*a  end
  print(square, square(2))
'
#*
# Funções podem retornar vários valores
lua50 -e '
  function foo()  return 1, 2, 3  end
  print(1, 2, 3)
  print(foo())
  print(99, foo())
  print(99, foo(), 200)
  print(99, (foo()))
  zero, um, dois, tres, quatro = 0, foo()
  print(zero, um, dois, tres, quatro)
'
#*
# Coerção
lua50 -e '
  print(1+"2")
  print("<".. 11 .. 22 ..">")
'
#*
# Tables
echo $LUA_INIT
lua50 -e '
  a = {10, 20, 30}
  print(200, "um string", a)
  PP   (200, "um string", a)
  b = {11, a, "foo", print}
  PP(b)
'
#*
# Tables (2)
lua50 -e '
  c = {11, 22, 33}
  c[2] = c[2]+c[3]
  c[5] = 55
  c["foo"] = "FOO"
  PP(c)
  d = {11, 22, 33, [5]=555, ["bar"]="BAR", [c]="!"}
  PP(d)
  d[2] = nil
  d[c] = nil
  PP(d)
'
#*
# Variáveis globais
lua50 -e '
  for key,val in _G do
    print(key, val)
  end
'
#*
# Variáveis globais
lua50 -e '
  print(print)
  print(_G["print"])
  print(_G.print)
  print(_G)
  print(_G._G)
'
#*
# Variáveis locais
lua50 -e '
  a = 22
  do print(a)
     local a = 33
     print(a)
  end
  print(a)
'
#*
# assert
lua50 -e '
  print(22)