💾 Archived View for separateconcerns.com › 2013-09-01-lapis.gmi captured on 2023-04-19 at 22:58:56. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-03-01)
-=-=-=-=-=-=-
published 2013-09-01
I use different programming languages for different tasks, but the one I prefer is Lua [1]. I have always wanted to use it for the Web, and in a way I already do: this blog is a static website generated by a custom Lua program. I have also written several services that can speak HTTP+JSON in Lua. For larger, HTML-based Web applications however, I have never found the framework I wanted. I have tried several [2] of [3] them [4], but kept coming back to more dependable platforms [5].
Last March, I gave Lapis [6] a try. It is a relatively new framework written by Leaf Corcoran [7], the author of MoonScript [8], a programming language that compiles to Lua (like CoffeeScript for JavaScript). Lapis is powered by OpenResty [9], an incredibly fast [10] web application server that run inside the nginx [11] Web server and is already used by large websites like Taobao [12] and CloudFlare [13].
Lapis was built with MoonScript in mind, so I had to hack around it to make it work with plain Lua. It worked but was too verbose, so I eventually gave up [14] on that and on Lapis altogether. But that was Lapis version 0.0.1! Leaf continues to improve it and recently released version 0.0.4. Last Friday evening, on a train to Bordeaux, I decided to give it another try.
Lapis now natively supports Lua [15] and has improved in various aspects. I have found it comfortable to write the views and the configuration file with the MoonScript DSLs provided by the framework. For logic (models and controllers) I used Lua directly since I prefer its syntax to MoonScript for regular code.
I have published a small skeleton application [16] which demonstrates this dual languages style to GitHub. I chose to use Redis for the datastore because I know it well and had it running on my laptop, so I did not use the database integration layer of MoonScript which is designed primarily for PostgreSQL (but it looks nice as well). This application is a kind of Hello World but it demonstrates most features of the framework, including sub-applications [17], widgets [18], layouts [19], exception-handling [20] and input validation [21].
If you want an example of a larger Lapis codebase with a different style, MoonRocks [22] is written in Lapis and its code is on GitHub [23].
So, what did I think of it? Well, finally I could see myself write a serious Web application in Lua! I will still choose Python and Flask in a professional setting because it is is a more stable, more feature-complete stack, and because I would not want to ask a whole team to learn both Lua and MoonScript to work on the project. But if I make a Web application as a personal side project, I will certainly try to use Lapis for that.
2: http://www.keplerproject.org/en/Orbit
3: https://github.com/zedshaw/Tir
4: https://github.com/nrk/mercury
10: http://www.techempower.com/benchmarks/
12: http://en.wikipedia.org/wiki/Taobao
13: https://www.cloudflare.com/
14: https://github.com/catwell/fun-with-lapis/commit/42af204c6974f124c2b4856102e260d8ad7baca6
15: http://leafo.net/lapis/reference.html#lapis-in-lua
16: https://github.com/catwell/badakhshan
17: http://leafo.net/lapis/reference.html#lapis-applications-sub-applications
18: http://leafo.net/lapis/reference.html#html-generation-html-widgets
19: http://leafo.net/lapis/reference.html#html-generation-layouts
20: http://leafo.net/lapis/reference.html#exception-handling
21: http://leafo.net/lapis/reference.html#input-validation