|
|
Edrx's page on Lua, Forth, and in-betweens
(As of sep/2005 most of the stuff below is at least two years old -
which means obsolete, broken, and incorrectly converted to blogme format. Sorry.)
Quick index:
Lua:
1. A lua-mode for Emacs
;; Relevant code in my .emacs:
;; (find-angg ".emacs" "add-to-alist")
;; (find-angg ".emacs" "auto-mode-alist")
(add-to-list 'load-path "~/elisp/")
(add-to-alist 'auto-mode-alist '("\\.lua$" . lua-mode))
;; (find-angg ".emacs" "lua-mode")
(setq lua-indent-level 2)
(setq lua-electric-flag nil)
(defun lua-abbrev-mode-off () (abbrev-mode 0))
(add-hook 'lua-mode-hook 'lua-abbrev-mode-off)
|
2. Running the Lua API interactively from GDB
Current directory is /home/edrx/usrc/lua-5.1.2/src/
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) set args /tmp/foo.lua
(gdb) br math_sin
Breakpoint 1 at 0x80673ef: file lmathlib.c, line 32.
(gdb) run
Starting program: /home/edrx/usrc/lua-5.1.2/src/lua_O0 /tmp/foo.lua
Breakpoint 1, math_sin (L=0x8071008) at lmathlib.c:32
(gdb) call lua_pushstring(L, "print")
(gdb) call lua_gettable(L, -10002)
(gdb) call lua_pushstring(L, "Foo!")
(gdb) call lua_pushstring(L, "Bar!")
(gdb) p lua_gettop(L)
$1 = 4
(gdb) call lua_call(L, 2, 0)
Foo! Bar!
(gdb) p lua_gettop(L)
$2 = 1
(gdb)
|
3. Gavin Wraith's functional syntax patch
4. Ldb
Lua for Debian:
- In 2001 I made the first publically-available Debian packages for
Lua (files, e-scripts).
- The current Debian packages are maintained by Daniel Silverstone,
and are excellent. Do:
- I have packaged Lua-4.0 for Debian. My patches and add-ons are in this directory, and there are instructions to compile my package
for other distros here. My package
includes:
- A TeXinfo version of the Lua reference manual (here is the .texi),
- A non-standard interpreter called
dllua that has:
- Reuben Thomas' functions
for bit operations and regexps,
- the
loadlib/unloadlib/callfromlib functions
from CGILua's loadlib.c,
- an extra API function,
dllua_open, that works as
lua_open but also loads all the standard
libraries, plus the bitops/regexps/loadlib libraries, into the
newly-created Lua_State.
Forth:
Forth-like languages interpreted on top of Lua:
- An outdated project: Flua. It has access to the
standard C library and to extensions written in C
and in other languages (see jcw's project Minotaur). I'm
planning to use Flua for the computational part of my ideas
about skeletons of mathematical proofs, and for adding cLIeNUX-like extensions to the Hurd.
- A follow-up to Flua: miniforth, and the bare
beginnings of a technical report on its
main ideas. It has the same goals as Flua, and it is much more
modular; the part that generates bytecodes for an inner
interpreter written in C is kept separate
from the rest.
- Note that both Flua and miniforth are far from being really
usable.
Important local links:
I gave a minicourse about Lua in 2004 (link?) and I'll give it
again (much updated, of couse!) at the beginning of October, at http://www.c3sl.ufpr.br/secomp/... Here is the current summary (in
Portuguese only, and still without links):
Curso de Lua
Resumo: Uma "introdução em profundidade" à linguagem de
programação Lua. Como a linguagem é bastante simples (o manual de
referência completo, incluindo a descrição de todas as funções e da
API em C, tem 65 páginas), será possível abordar todos os aspectos
principais da linguagem, e mais algumas extensões, ferramentas, e
várias técnicas de uso.
Tópicos:
- Instalando e rodando o Lua
- O núcleo do Lua:
- Tipos de dados; expressões e statements. Sintaxe. ";"s implícitos.
- Variáveis globais e locais; escopo.
- Tabelas associativas; como arrays, classes e variáveis globais são
implementados via tabelas.
- Funções como objetos; closures; blocos de código; propagação de
erros.
- Bibliotecas padrão:
- Suporte a I/O e arquivos.
- dofile, dostring e require.
- Operações sobre tabelas; modos de percorrer tabelas.
- Operações sobre strings; regexps em Lua.
- Carregando bibliotecas extras com loadlib.
- As entranhas do Lua:
- A biblioteca "debug".
- Byte-compilação, a máquina virtual interna do Lua, a pilha.
- Rodando o Lua passo a passo com gdb; examinando o conteúdo da
pilha. Seguindo passo a passo algumas funções Lua definidas em C.
A API do Lua.
- Executando scripts e funções Lua a partir de C.
- Algumas bibliotecas e extensões: bitlib, pcre, posixlib, luagtk.
- Uma ferramenta para ligar Lua e C mais facilmente: tolua.
Pré-requisitos (aluno): inglês técnico básico (para entender a
documentação), alguma familiaridade com C (para quem quiser acompanhar
a parte final do curso).
Links:
|