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
of
them
, 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.

责编内容by:Separate Concerns (源链)。感谢您的支持!

您可能感兴趣的

NetMon Freemium – Use case : Detect non-encrypted ... This is one of the few times that I have written about a product for a company that I am working for. NetMon, or Network Monitor by LogRhythm is i...
lightweight concurrency in lua Hello, all! Today I'd like to share some work I have done recently as part of the Snabb user-space networking toolkit . Snabb is mainly about...
lightweight concurrency in lua Hello, all! Today I'd like to share some work I have done recently as part of the Snabb user-space networking toolkit . Snabb is mainly about...
我们能用lua做什么 lua是一个巴西人设计的小巧的脚本语言,它的设计目的是为了能够嵌入到应用程序中,从而为应用程序提供灵活的扩展和定制功能。 作为web开发工程师,我们平时主要使用的开发语言是php。这个语言提供了对html模版的强大的处理能力,也提供了十分丰富的函数库及扩展,非常的适合web开发使用。那么lua是...
【现学现卖】IntelliJ+EmmyLua 开发调试Unity中Xlua... 孙广东 2017.8.23 http://blog.csdn.NET/u010019717 推荐一下这个国人弄的基于 IntelliJ IDE 弄得插件 EmmyLua 。 他的QQ群: 29850775 github: https://github.com/...