lua-eco(中文)
Lua-eco is a Lua interpreter with a built-in libev event loop. It makes
all Lua code running in Lua coroutines
so code that does I/O can be
suspended until data is ready. This allows you write code as if you're using
blocking I/O, while still allowing code in other coroutines to run when you'd
otherwise wait for I/O. It's kind of like Goroutines
.
Lua-eco also provides some modules including timer, file, signal, exec, socket, http, ssl, dns, termios, ubus and so on.
Would you like to try it? Kinda interesting.
#!/usr/bin/env eco
local time = require 'eco.time'
eco.run(function(name)
while true do
print(time.now(), name, eco.id())
time.sleep(1.0)
end
end, 'eco1')
eco.run(function(name)
while true do
print(time.now(), name, eco.id())
time.sleep(2.0)
end
end, 'eco2')
- libev - A full-featured and high-performance event loop
sudo apt install -y liblua5.3-dev lua5.3 libev-dev libssl-dev
git clone --recursive https://github.com/zhaojh329/lua-eco.git
cd lua-eco && mkdir build && cd build
cmake .. && sudo make install
- websocket
If you would like to help making lua-eco better, see the CONTRIBUTING.md file.