• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ignacio/LuaNode: Asynchronous I/O for Lua

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

ignacio/LuaNode

开源软件地址(OpenSource Url):

https://github.com/ignacio/LuaNode

开源编程语言(OpenSource Language):

Lua 63.7%

开源软件介绍(OpenSource Introduction):

LuaNode

Build Status Build status License

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")
end):listen(8124)

console.log('Server running at http://127.0.0.1:8124/')

process:loop()

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.

Building

LuaNode can be compiled on Windows, Linux and OSX, using CMake. Although there are makefiles and projects for Visual Studio in the build folder, they are not really meant for general use. Currently, the recommended way to build is by using CMake 2.6 or above.

It is regularly built on:

  • Ubuntu 12.04 (precise)
  • Debian (squeeze, wheezy, jessie)
  • Windows 7, 8 and Server 2012 R2

LuaNode depends on the following:

Debian installation

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://github.com/ignacio/LuaNode.git
  • cd LuaNode/build
  • cmake ..
  • cmake --build .

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

  • git clone git://github.com/ignacio/LuaNode.git
  • cd LuaNode/build
  • cmake -DCMAKE_INSTALL_PREFIX=/usr ..
  • cmake --build .

If you do not want to or cannot use CMake, 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
  • 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.59)

    • Download boost_1_44_0.tar.bz2
    • Unpack
    • ./bootstrap.sh
    • 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://github.com/ignacio/LuaNode.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.

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://github.com/ignacio/LuaNode.git
  • cd LuaNode/build
  • cmake ../
  • make

Status

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

Documentation

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.

Acknowledgements

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).

License

LuaNode is available under the MIT license.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
scoder/lupa: Lua in Python发布时间:2022-08-16
下一篇:
pandoc/lua-filters: A collection of lua filters for pandoc发布时间:2022-08-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap