July 3, 2012
I recently gave a talk at Open Source Bridge about luvit, this great platform we are building that is like node.js only using lua as the implementation language.
Anyways, my slides are available but I wanted to create a slide by slide blog post with my notes too. So here goes!
Also, if you are in Portland for OSCON I will be giving a talk (update: slides posted) about how we are building an on server monitoring agent for Rackspace Cloud Monitoring on top of luvit. I will cover why we were interested in using luvit, how luvit works and how we are embedding it in our monitoring agent.

Luvit is a platform for building your app in an event driven manner.
Notes: luvit is scrawny like Mr. Stardust and uses very little memory. luvit is a young project and still growing, expect awkwardness. lua is Portuguese for moon so it is space themed just like Ziggy. There is a great community with a good sense of humor (luv_handles are a great data structure name)
local http = require("http")
http.createServer(function (req, res)
local body = "Hello world\n"
res:writeHead(200, {
["Content-Type"] = "text/plain",
["Content-Length"] = #body
})
res:finish(body)
end):listen(8080)
print("Server listening at http://localhost:8080/")
Notes: This code works today. It serves up an HTTP 1.1. server on 8080 that tells you Hello!
Notes: There is a great community of people working on this project. The best part is how many people are interested in different uses- not just web stuff. In particular Rackspace is interested in a really small memory footprint monitoring agent.
Notes: Lua shares a lot of features with javascript like using floating point numbers only, being dynamic and having first class functions. It is like node’s long lost Brazilian cousin
Notes: luajit is an alternative tracing VM for lua that has a great FFI layer. It is small and fast.
Notes: Essentially libuv is just a big loop (see the next section) that runs poll on a bunch of file descriptors with the timeout of the poll set to the next timer that needs to run. When the poll complete a callback is made so the user can handle the event. I have talk on libuv that covers all the details too
Notes: A number of new platforms are using libuv. Rust is a new language from mozilla. candor is a limited subset of javascript. luvmonkey is mozilla’s spidermonkey with libuv. http://julialang.org/ is also using libuv.
git clone git://github.com/luvit/luvit.git
cd luvit
./configure
make -C out
tools/build.py test
./out/Debug/luvit
Welcome to the Luvit repl
>
make
make test
./build/luvit
Welcome to the Luvit repl
>
local Object = require('core').Object
local Rectangle = Object:extend()
function Rectangle:initialize(w, h)
self.w = w
self.h = h
end
function Rectangle:getArea()
return self.w * self.h
end
local rect = Rectangle:new(3, 4)
p(rect:getArea())
Notes: Lua doesn’t have an object system so we impelemted our own in order to do our inheritance of stream, event emitter, etc
local JSON = require('json')
local value = JSON.parse([[
{
"author": "Brandon Philips <brandon@ifup.org>",
"name": "luvit - node's Ziggy Stardust",
"description": "a talk about luvit"
}
]])
local json = JSON.stringify(value, {beautify=true,indent_string=" "});
print(json)
Notes: Luvit has a JSON parser using yajl. It has some nice features like allowing comments
Notes: There are a number of users of luvit today. Lets see some of them
Thanks to the luvit community for all of their hard work. Also thanks to Rackspace for letting me do work in the open.