Lua is… well, it’s a programming language. I don’t know it well enough to classify it as functional, imperative, or what have you (I’m fairly sure it isn’t declarative) I haven’t actually tried it yet (something I need to rectify at some point, but I’ve liked what I’ve read.
Most of what I’ve read comes from The Evolution of Lua, a rather fascinating paper, which like most programming language stuff, I got through Lambda The Ultimate (lambda_ultimate – I originally discovered it when LJ introduced their feed syndication, but I mostly read it through Bloglines these days)
What I remember from the paper, is that Lua is a language with a few big ideas, and I love big ideas. First of all, it’s mission in life is to be an embedded language. It is designed to be easily integrated into C programs (and most everything else has a C interface), supporting both call-by and call-to C.
Secondly, the language itself has a core concept. FoxPro has databases, Lisp has S-expressions (typically lists), ML tries to represent mathematical logic, and Smalltalk embraced objects to make a one-page language spec. Lua embraces hash tables. So what? Well, you can do pretty much anything with them. Hash tables are obvious; objects have named properties (hash keys), and arrays just happen to have numerical keys. Someone in a lisp context said it is better have 100 operations on one thing than 10 operations on 10 things.
Inefficient you cry? Current versions of the interpreter will only build half the hash if it can. If you use it as a set (only dealing with keys), it doesn’t allocate space for the values. If you use it as an array (numerical keys only), it doesn’t allocate the keys. If you find a bottleneck, write a C function and call it from Lua code – Lua’s mission is to be quick and powerful scripting language, not a core engine language.
Since then, Lambda the Ultimate also turned up Metalua. Meta-programming is one of those things that is hard to explain if you don’t understand it. C templates are a limited example. The Lisp macro system is legendary for being able to make the language do just about anything. (An ordinary Lisp file, to be included in your project, which allowed one to use Python style spacing instead of the infamous parentheses may have been using this.) The examples given for Metalua are not trivial – adding type checking to the language, and pattern matching in the ML style (think of it as a ‘switch’ statement on the structure of the argument, rather than the value.)