Node's Ziggy Stardust

Brandon Philips
brandon@ifup.org
May 17, 2012

Features in Luvit

HTTP Server

local http = require("http")

http.createServer(function (req, res)
  local body = "Ground control to Major Tom\n"
  res:writeHead(200, {
    ["Content-Type"] = "text/plain",
    ["Content-Length"] = #body
  })
  res:finish(body)
end):listen(8080)

print("Server listening at http://localhost:8080/")

HTTP Client

local http = require('http')

http.request({
  host = "127.0.0.1",
  port = 80,
  path = "/"
}, function (res)
  res:on('data', function (chunk)
    p("ondata", {chunk=chunk})
  end)
  res:on("end", function ()
    res:destroy()
  end)
end)

Scrawny

Lua - Javascript's Long Lost Brazilian Cousin

Tables, tables, tables

GroundControl = {}

function GroundControl.new()
  obj = {}
  obj.var = 1
  setmetatable(obj, { __index = GroundControl })
  return obj
end

function GroundControl:print()
  print(self.var)
end

a = GroundControl.new()

a:print()

a.print() -- error!
        

libuv - I/O event loop magic

FFI is awesome! And Fast.

Call C functions without writing C

local ffi = require("ffi")

ffi.cdef[[
  int printf(const char *fmt, ...);
]]

ffi.C.printf("Hello %s!\n", "world")

The Future

ifup.org/slides

Thanks! - fork on luvit.io - contact me: brandon@ifup.org

Source: Octodex