2006 September 02 20:48
I’m officially excited about the Lua programming language.
Lua is a small, elegant language, very carefully designed and implemented, with many, if not all, of the features that I want:
- anonymous functions (lambdas) and closures;
- lexical scoping;
- proper tail-recursion;
- a resident compiler;
- embeddability, in both senses: it can be used as an extension language, and can run on “embedded” (and rather modest) hardware;
- extensibility – it can be extended, both in itself (ideally via some kind of metaprogramming), or in C.
Lua has three “implementation” features that are important to me:
- the primary documentation (book and reference manual) is written by the designer and primary implementor;
- there is an authoritative, high-performance implementation by the language’s designers (unlike, say, Scheme, which has so many implementations that it’s impossible to choose a “good” one);
- the implementation is small enough to understand and modify.
Philosophically Lua appeals to me. Everything about it is small. There are few key ideas, but they are good ones. The implementation is tiny. The language is tuned for size and speed, but because it’s designed to be linked to other code, it’s also designed for comprehensibility. And again, that means the smaller the better (since we can only use masterfully something we deeply understand). Lua is a convivial tool.
While most languages are profligate, Lua is parsimonious. The syntax is simple, the semantics straighforward; there few rules and fewer exceptions. The implementation is, by modern standards, tiny: a full host (x86) binary is ~140k bytes. It’s straightforward to slim this down to ~40k or less for use on small embedded devices.
Like all interpreted languages, Lua has the feature that data constructors and function definitions are executable code. This means that configuration files (for instance) are executable code. No longer is it necessary to write parsers for them; simply read them into Lua!
This fact, coupled with Lua’s clever – and only! – structured data type – the table – makes possible not only self-documenting XML-like structured data, but also data that, when executed, can produce an HTML (or XML – think RSS!) rendering of itself.
- Why I think Lua is a convivial tool
- An executive summary of Lua
- Programming in Lua, first edition. Covers version 5.0. The second edition is out in paperback; it covers Lua 5.1.
- Lua 5.1 reference manual
- An interesting history of Lua’s development
- A description of Lua 5’s innovative virtual machine
- Two articles championing its use (same author, different years)
- What users are saying
- Some applications of Lua (lots of computer games!)
- Lua user’s wiki