Skip to content

Lua API reference manual

zhaojh329 edited this page Jun 4, 2017 · 11 revisions

Install lua-ev

On Ubuntu

git clone https://github.com/brimworks/lua-ev.git
cd lua-ev
cmake .
make
sudo mkdir -p /usr/local/lib/lua/5.1
sudo cp ev.so /usr/local/lib/lua/5.1

On OpenWRT/LEDE

git clone https://github.com/zhaojh329/lua-ev-openwrt.git
cp -r lua-ev-openwrt OpenWRTDIR/package/lua-ev
cd OpenWRTDIR
make menuconfig
	Languages  --->
	Lua  --->
		<*> lua-ev
make package/lua-ev/compile V=s

API for evmongoose

init

Init mgr context, return a handle

local ev = require("ev")
local evmongoose = require("evmongoose")
local loop = ev.Loop.new()
local mgr = evmongoose.init(loop)

bind

Listens for the specified address, can plain tcp or http or https.

mgr:bind("8000", ev_handle)
mgr:bind("8000", ev_handle, {document_root = "/www"})
mgr:bind("8000", ev_handle, {ssl_cert = "server.pem", ssl_key = "server.key", document_root = "."})

connect_http

connect to http or https server

mgr:connect_http("http://www.baidu.com", ev_handle)
mgr:connect_http("https://www.baidu.com", ev_handle, {ssl_cert = "server.pem", ssl_key = "server.key"})
Clone this wiki locally