Lua

2009-01-08

So, I’ve been using Lua for a couple of months now; I thought that I would learn it because it’s been ages since I learned a new language, and it’s got a reputation for being small, clean and fast.

On the whole I think it’s lives up to it’s reputation. It’s a nice langauge, leaning more toward the functional than OO, at least in the way that I write it.

Syntactically, it’s very simple and regular which is a good thing; there are a very places where I would have simplified it still further. For example, both of these are legal:

print( "hello" )
print "hello"

which is a nice syntactic short-cut, but then it only works with a single argument,

print( "hello", "goodbye" )
print "hello", "goodbye" -- ILLEGAL

Probably I would not have allowed the shortcut.

Lua has a pattern syntax for regexp-like searching, but in a desire to keep Lua small, it’s a pretty weak; more over, it’s not a standard syntax at all, and lacks familiarity. Of course, Lua makes it easy to link in a regexp library, but I think that they should have standard extensions — i.e. if you are going to link in a regexp library choose this one first. To some extent, this already happens — the Math.power function is not guarenteed to work as it forces the linking of the ansi C math library.

Almost all of Lua is based around tables — hash maps effectively — which also serve as arrays. This is okay and, of course, you can build anything you want from this; but, combined with the lack of types, I find myself asking questions like, is this a table of tables, an array of tables or a table of arrays? Too much knowledge is implicit. Table handling is also a bit limited; there’s no support for taking slices of tables (when used as an array), nor functions like "contains" or "first index".

On the whole I think it fulfils it’s purpose; it’s great for small and simple code. The worry is that people will get carried away and start writing enormous applications in it, for which it is just not suited. Small languages have a habit of becoming big. As it is, though, it serves as a nice, relatively low-level language.

Originally published on my old blog site.