Version 21 of Lua

Updated 2005-09-04 12:35:46

Lua [L1 ] is one of the many languages with a Tk binding. A vaguely C-styled OO scripting language developed "half-open source" at a Brazilian institution, characterized by using hash tables as central data structure, even for vectors and lists. Lua's kernel is unusually compact. Lua style emphasizes metaprogramming.

Roberto published the Lua book [L2 ] early in 2004. Lua has its own Wiki [L3 ].

Lux [L4 ] is Jean-Claude Wippler's experiment at binding Lua together with more traditional scripting languages ...

Max Ischenko reports success using SWIG to wrap Lua libraries as loadable .so-s exposed through Tcl. He even has an incr Tcl class he calls "LuaInterpreter".

mfi: Yup, that was pretty simple. To compile a .so you just do:

 swig -tcl8 -module lua Lua.i
 gcc -c -fpic lua_wrap.c
 gcc -shared lua_wrap.o -o lua.so -llua -llualib

And the abovementioned itcl class is a little more complex than this sketch:

 itcl::class LuaInterpreter {
        public {
                method doFile fname { return [lua_dofile $L $fname] }
                method doString buf { return [lua_dostring $L $buf] }
                method call {func {arg ""}} {}

                method popLast {} {
                        set value [lua_tostring $L -1]
                        lua_remove $L -1
                        return $value
                }
                method printStack {} {}
        }
        constructor {} {}
        destructor { lua_close $L }
        common call_template "return %s(%s);"
 }

 itcl::body LuaInterpreter::constructor {} {
        set L [lua_open 1024]
        L doString "function _ERRORMESSAGE(msg) print(msg) end"
 }

 itcl::body LuaInterpreter::call {func {arg ""}} {
        set op [format $call_template $func $arg]
        doString $op
 }

I found the interface of doString, call and popLast quite sufficient for my needs. Notice also, that you can have as many instances of Lua interpreter as you want. --mfi.


Lua is quite fast: http://www.bagley.org/~doug/shootout/ but doesn't seem to have all the nifty features that other languages do.

On another hand, Lua does support full co-routines; Roberto is a sometimes-cited theoretician of concurrency.


CL sometimes collects Lua references [L5 ].


While Lua began with an emphasis on industrial automation and allied areas, it's now so significant in game development that Game Scripting Mastery [L6 ] and Game Programming with Python, Lua, and Ruby [L7 ] provide substantial introductions to it.


An article about Lua's byte code engine: http://www.osnews.com/comment.php?news_id=9817

Apparently they moved from a stack based to a register based engine and saw big performance improvements.


WJP A real weakness of Lua when compared to Tcl is its feeble regular expression support. Lua regexps don't have groups. The quantifiers apply either to the preceding symbol or the preceding builtin character class. (Lua does have capture groups, for use with backreferences, but they do not serve as quantifier domains.) Lua lacks the range quantifiers (e.g. {2,4} = "from two through four inclusive") found in any POSIX regexp package. It does not permit characters to be specified using the usual octal and hex escapes, and it does not have any of the recent innovations such as assertions. If you're doing anything involving more than simple regexp matching, Lua just doesn't cut it. Tcl has one of the best regexp packages. Lua has perhaps the poorest. Lua also does not support Unicode. It is 8-bit clean but has no concept of multibyte or wide character.

Lars H: In other words, the Lua "regexps" are really more of a beefed-up string match than real regular expressions. (For those who don't know regexp theory: There is a very strict definition of regular expression that has its roots deep down in computer science and mathematics. The abilities to have alternative branches and repetition of arbitrary subexpressions are essential parts in this definition; losing them loses most of the power of the concept. Character classes, hex escapes, range quantifiers, lookahead constraints etc. are on the other hand "just" syntactic sugar that helps reducing the size of the regexp (often a significant reduction, but one can do without them). The "back reference" feature of Tcl regexps does however go beyond what pure regular expressions should be capable of.)

WJP: Yes, good characterization. Alternation and closure of subexpressions are essential for true regular expressions but Lua has alternation and closure only for singletons. As for syntactic sugar, its true that in some sense it is less important, but some syntactic sure makes a huge difference in practice. It would not be much fun to have to write out [abcdefghijklmnopqrstuvwxyz] every time instead of [:lower:], and its even worse if you're looking at all of Unicode. After all, Tcl is only "syntactic sugar" on machine language. They're both Turing complete in principle, and both just finite state transducers in practice (assuming a finite universe and therefore computers with a finite set of states). Lua has one construct that I've never seen anywhere else: %bXY (%b constant, X and Y variables over characters) matches a string beginning with an X and ending in a Y. It looks like its intended for matching balanced delimiters.


Category Language