Lapis: Lua for the Web

科技动态 2013-09-02

I use different programming languages for different tasks, but the one I prefer is Lua
. 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
, but kept coming back to more dependable platforms

Last March, I gave Lapis
a try. It is a relatively new framework written by Leaf Corcoran
, the author of MoonScript
, a programming language that compiles to Lua (like CoffeeScript for JavaScript). Lapis is powered by OpenResty
, an incredibly fast
web application server that run inside
the nginx
Web server and is already used by large websites like Taobao
and CloudFlare

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
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
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
, widgets
, layouts
, exception-handling
and input validation

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

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.


Tarantool 101, Guide 3: Spawning With Fibers and C... Tarantool 101, Guide 3: Spawning With Fibers and Channels DZone's Guide to Tarantool 101, Guide 3: Spawning With Fibers and Channels ...
Corner Cutting vs. Productivity I recently got into a discussion with another very knowledgeable Rustacean, who (I paraphrase) claimed that Rust is about adding just enough roadbloc...
Securing static resources with cookies, nginx, and... I've been working with one of my clients the last month on migrating his iron- based architecture to a cloud-based provider. In this transition, we ar...
Redis Lua 脚本使用 Lua 简介 Lua语言提供了如下几种数据类型:booleans(布尔)、numbers(数值)、strings(字符串)、tables(表格)。 下面是一些 Lua 的示例,里面注释部分会讲解相关的作用: -- -- -- 拿客 -- 网站
Typed Architectures: architectural support for lig... Typed Architectures: architectural support for lightweight scripting Kim et al., ASPLOS’17 JavaScript, Python, Ruby, Lua, and related dynamical...