-- Leo's gemini proxy

-- Connecting to separateconcerns.com:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini;lang=en_US

Lapis: Lua for the Web

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 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 [14] 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 [15] 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 [16], widgets [17], layouts [18], exception-handling [19] and input validation [20].


If you want an example of a larger Lapis codebase with a different style, MoonRocks [21] is written in Lapis and its code is on GitHub [22].


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.


1: http://www.lua.org/

2: http://keplerproject.github.io/orbit/

3: https://github.com/zedshaw/Tir

4: https://github.com/nrk/mercury

5: http://flask.pocoo.org/

6: http://leafo.net/lapis/

7: http://leafo.net/

8: http://moonscript.org/

9: http://openresty.org/

10: http://www.techempower.com/benchmarks/

11: http://nginx.org/

12: http://en.wikipedia.org/wiki/Taobao

13: https://www.cloudflare.com/

14: http://leafo.net/lapis/reference.html#lapis-in-lua

15: https://github.com/catwell/badakhshan

16: http://leafo.net/lapis/reference.html#lapis-applications-sub-applications

17: http://leafo.net/lapis/reference.html#html-generation-html-widgets

18: http://leafo.net/lapis/reference.html#html-generation-layouts

19: http://leafo.net/lapis/reference.html#exception-handling

20: http://leafo.net/lapis/reference.html#input-validation

21: http://rocks.moonscript.org/

22: https://github.com/leafo/moonrocks-site

-- Response ended

-- Page fetched on Sun May 12 11:09:45 2024