Running lua on heroku

在heroku上运行lua。

作者：leafo

在Heroku云上部署Lua应用

Running Lua on Heroku

Posted February 05, 2012 by leafo (@moonscript)

Since the release of Heroku’s Cedar platform they've opened up the opportunity for users to run web applications on any stack. Using something called a buildpack we can describe a template for deploying any kind of application. I saw this as a great opportunity to try using Lua on a cloud hosting platform (for free).

I put together heroku-buildpack-lua, a buildpack containing Lua 5.1 andLuaRocks (a Lua package manager) enable you to quickly deploy Lua along with any required dependencies that can be found on theLuaRocks server.

1.创建APP

Clone the repository it created and we're ready to begin. (stark-dust-4830 was the randomly generated name of my app, replace it with yours.)

克隆分支，创建后我们开始读取。(stark-dust-4830是一个随机生成app名称)

$ git clone git@heroku.com:stark-dusk-4830.git
$cd stark-dust-4830

2.描述依赖

Describing Dependencies

Heroku manages a collection of app servers for us, called web dynos in their terminology. Each application server must expose itself to the outside world. This is done by running a web server on the dyno.

Heroku为我们管理服务器上的应用集合， 术语叫做web dynos，每个应用服务必须对外界暴露自己，这是运行在dyno上的WEB服务。

The Xavante project is simple web server written in Lua with a couple dependencies.

Xavate project是一个简单的用lua弄的web服务，两依赖。

Using LuaRocks bundled in the Lua buildpack, we can easily install Xavante and all its dependencies. We describe the dependencies of our Lua project by creating a rockspec for it.

A rockspec is a special Lua file ending in .rockspec that describes meta-data about a Lua module. This meta-data includes things like the project name, the maintainer. It also holds any dependencies and how to build the module.

In this file we create a web server with two simple rules. If you go to the path / then we say hello and show the time. Otherwise, we default to trying to serve files from the static/ directory in our app.