Brandon Philips
brandon@ifup.org
May 17, 2012
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/")
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)
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!
Call C functions without writing C
local ffi = require("ffi") ffi.cdef[[ int printf(const char *fmt, ...); ]] ffi.C.printf("Hello %s!\n", "world")