I spent much of my spare time over the weekend playing with the Lua Lua programming language and Kepler web framework. It was amusing, I wouldn’t mind playing with Lua a bit more some day, but I think I’ve gone about as far with it as I care to for right now. Before I go, I figure I’ll share some thoughts and impressions.

To start with, Lua reminded me a lot of Python. It has the same very visible relationships between tables (dictionaries in Python), objects, and modules. The meta-programming looks very similar too. It’s kind of like a very stripped down, almost primitive, version of Python, though. The documentation on object orientation or module structure contains not so much descriptions of how those things are done in Lua as examples of how other people have done them in Lua. On the object front, Lua has no established object model; you just use meta-programming to build your own. There are some very small nods (e.g. the colon operator) to object orientation, but it never extends very far. Even operations on built-in types often involve passing them as arguments to library functions instead of calling methods on them. On the module front there is a module function, but using it tends to pollute the global namespace (in this it reminds me of PHP more than Python) so there are multiple suggestions of how else to do the same thing. Opposite to Python, which has a “global” keyword to make things explicitly global, Lua has a “local” keyword to do the exact opposite. One area where Lua’s drive for simplicity seems to have gone too far is in eschewing “normal” lists or arrays in favor of having tables do that as well – and do it poorly. Having to use pairs(x) for tables which are used as objects/dictionaries and ipairs(x) for tables which are used as arrays/lists is just awkward, and one-based addressing (also used for strings) feels positively COBOLian. Overall, the language seems designed around flexibility and ease of implementation, which are fine goals but a little bit of a shock compared to languages designed more explicitly to maximize programmer productivity.

OK, enough about the language. How about the Kepler framework? I started out trying to use Orbit, but it didn’t take long at all for me to get tired of all the MVC-ish-ness so I mostly just used WSAPI without it. I pretty quickly figured out how to do the kind of request dispatch I wanted on my own, and Cosmo seemed to do fine for templates – although I didn’t exactly stress it much. I barely even noticed the Copas/Coxpcall/Rings parts except for using coroutine.yield in handlers, and Xavante seemed to work just fine as a server. Then I kind of hit a wall when I tried to figure out how to do PUT of large files. There seem to be several recipes out there for handling POST of files up to 4GB as forms, but the neither documentation nor forum searches nor perusal of the code seemed to show any way to do a chunked upload bigger than that. The obvious ways of reading from wsapi_env.input all yielded poor results, which seemed to have something to do with WSAPI wraps things in coroutines but I never quite got to the bottom of it. (This tendency toward too-clever and too-fragile use of meta-programming instead of doing things in a more straight-forward way seems quite pervasive in Lua code and had also bugged me in Orbit.) On a similar subject, Lua seems to have no real native threading, though there are documents describing how to do it (and how you’ll get stuck on locks around the Lua core) in extensions. Coroutines just don’t cut it in a multi-core world, and I couldn’t convince myself that Lua’s implementation even allows for effective use of a single core, which puts a serious dent in my interest level.

In the end, I just don’t feel like Lua’s a good fit for the kind of program I decided to use for this experiment. In a different problem domain the flexibility and the ease of extension/embedding and the awesome performance of LuaJIT might make it a much better choice, but for now I’m debating whether to try JavaScript or Ruby (or maybe Clojure) next.