lua-eco
lua-eco copied to clipboard
🐛Lua-eco is a Lua interpreter with a built-in event loop for scheduling lightweight coroutines automatically, enabling efficient concurrency in Lua. Build high-performance, scalable applications.
lua-eco(中文)
Lua-eco is a Lua coroutine
library which was implemented based on IO event
.
Including time, socket, ssl, dns, ubus, ip, iw, and more which will be added in the future.
Would you like to try it? Kinda interesting.
local eco = require "eco"
local time = require "eco.time"
local socket = require "eco.socket"
local function handle_client(c)
while true do
local data, err = c:recv()
if not data then
print(err)
break
end
c:send(data)
end
end
eco.run(
function()
local s = socket.tcp()
local ok, err = s:bind(nil, 8080)
if not ok then
error(err)
end
s:listen()
while true do
local c = s:accept()
local peer = c:getpeername()
print("new connection:", peer.ipaddr, peer.port)
eco.run(handle_client, c)
end
end
)
eco.run(
function()
while true do
print(time.now())
time.sleep(1.0)
end
end
)
eco.loop()
Requirements
- libev - A full-featured and high-performance event loop
Build
sudo apt install -y liblua5.3-dev lua5.3 libev-dev libmnl-dev libssl-dev
git clone --recursive https://github.com/zhaojh329/lua-eco.git
cd lua-eco && mkdir build && cd build
cmake .. && sudo make install
Reference
Contributing
If you would like to help making lua-eco better, see the CONTRIBUTING.md file.