LuvitLua實(shí)現(xiàn)的Node.js
Luvit - Lua + UV + Jit = NodeJS re-implemented in Lua
如上面標(biāo)題所描述的,Luvit 相當(dāng)于 luajit2 + libuv,編譯成單個(gè)可執(zhí)行文件,類似 Node.js ,可運(yùn)行 .lua 文件。
示例代碼(創(chuàng)建一個(gè)HTTP服務(wù)器)
-- Load the http library
local HTTP = require("lib/http")
-- Create a simple nodeJS style hello-world server
HTTP.create_server(function (req, res)
res:write_head(200, {
["Content-Type"] = "text/plain",
["Content-Length"] = "11"
})
res:write("Hello World")
res:finish()
end):listen(8080)
-- Give a friendly message
print("Server listening at http://localhost:8080/")
評(píng)論
圖片
表情
