Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Asynchronous I/O for Lua

branch: master

Fix emit("error") with multiple listeners

If more than one error listeners were registered, emitting an error would
trigger an actual error instead of calling the listeners.

The test to determine if the listeners array is empty was utterly wrong...
Since the beginnig of time...
latest commit bca3678ec4
Ignacio Burgueño authored
Octocat-spinner-32 build Fix build with Lua installed with apt February 25, 2014
Octocat-spinner-32 deps Updated stacktraceplus to latest master December 03, 2013
Octocat-spinner-32 lib Fix emit("error") with multiple listeners March 18, 2014
Octocat-spinner-32 src Removed old comment December 23, 2013
Octocat-spinner-32 test Fix emit("error") with multiple listeners March 18, 2014
Octocat-spinner-32 tools Fix error when a socket is closed while connecting. May 13, 2013
Octocat-spinner-32 .gitignore Bring the net code up to date with Node v0.8.23 June 03, 2013
Octocat-spinner-32 .travis.yml Remove dependency with LuaSocket October 30, 2013
Octocat-spinner-32 CMakeLists.txt Remove dependency with LuaSocket October 30, 2013
Octocat-spinner-32 LICENSE Added license and readme December 14, 2010
Octocat-spinner-32 Added OS X Mountain Lion December 03, 2013
Octocat-spinner-32 luanode_api.h Added luanode api and .gitignore November 04, 2010


Build Status

Asynchronous I/O for Lua.

LuaNode allows to write performant net servers or clients, using an asynchronous model of computing (the Reactor pattern). You might have seen this model implemented in event processing frameworks like Node.js, EventMachine or Twisted. In fact, LuaNode is heavily based on Node.js, because I wanted to be able to do what Node.js does, but using Lua instead of JavaScript.

LuaNode is written using Boost.Asio. From its homepage:

Boost.Asio is a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach.

That allows LuaNode to be cross-platform. It is mainly developed on Windows, but it is being tested also on Linux and OSX.

Hello, world

The following is the "hello world" of HTTP servers.

local http = require('luanode.http')

http.createServer(function(self, request, response)
   response:writeHead(200, {["Content-Type"] = "text/plain"})
   response:finish("Hello World")

console.log('Server running at')


To run the server, put the above code in a file test_server.lua and execute it with LuaNode as follows:

luanode test_server.lua

Then point your browser to http://localhost:8124/

You'll notice a striking resemblance with Node.js example server. In fact, I've aimed at keeping both, within reason, to be quite compatible. Code from Node.js can be easily rewritten from JavaScript into Lua, and with a few more tweaks, you can adapt code available today for Node.js.


LuaNode can be compiled on Windows with Visual Studio 2008 or with GCC on Linux. Look on the build folder. At the moment, both VS projects and Makefiles are not usable without some heavy tweaking. Proper makefiles and projects (and also build instructions) will follow.

LuaNode depends on the following:

Debian installation

The following has been tested on Ubuntu Desktop 10.10 / Debian testing.

  • Install Lua and libraries

    • sudo apt-get install lua5.1 liblua5.1-0-dev liblua5.1-json
  • Install OpenSSL

    • sudo apt-get install libssl-dev
  • Install Boost

    • sudo apt-get install libboost1.46-dev libboost-system1.46-dev
  • Install Boost (tested with 1.44 to 1.47)

    • Download boost_1_44_0.tar.bz2
    • Unpack
    • ./
    • sudo ./bjam --build-type=complete --layout=versioned --with-system --with-thread threading=multi link=shared install
    • sudo ldconfig -v
  • Install LuaRocks

  • Install LuaNode

    • cd ~
    • mkdir -p devel/sources
    • mkdir -p devel/bin
    • cd devel/sources
    • git clone git://
    • cd LuaNode/build/linux
    • export INCONCERT_DEVEL=~/devel
    • make

When compiling on ArchLinux, the last step is this:

  • make PREFIX=/usr LIB_DIR=/usr/lib

Note: This installation procedure will be simplified in the future.

If you already have Lua, OpenSSL and Boost installed, you can use CMake to build LuaNode (thanks to Michal Kottman). Just do:

  • git clone git://
  • cd LuaNode/build
  • cmake ..
  • cmake --build .

    When build on ArchLinux, you need to change the install prefix, so the steps required are:

  • git clone git://

  • cd LuaNode/build
  • cmake -DCMAKE_INSTALL_PREFIX=/usr ..
  • cmake --build .

Mac OSX installation

Note: Installation was tested on OS X Lion 10.7.5, OS X Mountain Lion 10.8 and OSX Mavericks 10.9

If you don't have boost or cmake installed, you can use Homebrew:

  • brew install boost cmake

Compile from sources with cmake:

  • git clone git://
  • cd LuaNode/build
  • cmake ../
  • make


Currently, there's a lot of functionality missing. Doing a grep TODO should give an idea :D


Sorry, I've written nothing yet, but you can get along following Node.js 0.2.5 documentation.

The two most glaring difference between Node.js and LuaNode are:

  • Callbacks first parameters is always who is emitting the event.
  • Streams' end method is finish in LuaNode.
  • You must start the event loop yourself (this surely will change in the future).

The unit tests provide lots of examples. They are available at the test folder.


I'd like to acknowledge the work of the following people or group:

  • Ryan Dahl, obviously, for his work on Node.js and http-parser, which I use to parse http requests.
  • Renato Maia, for allowing me to take parts of Loop.
  • Keith Howe, for LuaCrypto
  • Michal Kottman, for his additions to LuaCrypto. He also contributed a CMakeLists.txt to ease building.
  • Steve Donovan, for allowing me to take parts of Penlight.
  • Joyent, for Node.js and libuv. Parts of libuv were adapted (terminal handling, etc).
  • Diego Nehab, for LuaSocket (which we use parts of).


LuaNode is available under the MIT license.

Something went wrong with that request. Please try again.