Fork me on GitHub

About Luvit

Luvit is an attempt to do something crazy by taking node.js' awesome architecture and dependencies and seeing how it fits in the Lua language.

This project is still under heavy development, but it's showing promise. In initial benchmarking with a hello world server, this is between 2 and 4 times faster than node.js. Version 0.7.0 is the latest release version.

Do you have a question/want to learn more? Make sure to check out the mailing list and drop by our IRC channel, #luvit on Freenode.

Version 0.7.0 Download

Installation From Source

It's easy! You can install Luvit just like you'd install any other Unix application:

From git

$ git clone https://github.com/luvit/luvit.git
$ cd luvit
$ make
$ make install

From a tarball

Download newest tarball first.

$ tar xvf luvit.tar.gz
$ cd luvit-0.7.0
$ make
$ make install

Prebuilt Binaries

Luvit is very easy to build, but in case you don't want to bother with a toolchain on your box, we provide binaries for OSX, Ubuntu, Raspberry PI, and Windows. Latest Luvit binaries.

Code samples

HTTP server

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/")

HTTP client

local http = require('http')

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

TCP echo server

local net = require('net')

net.createServer(function (client)

  -- Echo everything the client says back to itself
  client:pipe(client)

  -- Also log it to the server's stdout
  client:pipe(process.stdout)

end):listen(8080)
     
print("TCP echo server listening on port 8080")

TCP echo client

local net = require('net')

local client
client = net.createConnection(8080, '127.0.0.1', function (err)
  if err then error(err) end

  print("Connected...")

  -- Send stdin to the server
  process.stdin:readStart()
  process.stdin:pipe(client)

  -- Send the server's response to stdout
  client:pipe(process.stdout)

end)