@zwh8800
2017-08-23T10:23:19.000000Z
字数 498
阅读 190921
blog
归档
lua
node
lua 版的 nodejs
都听说过 nodejs 吧,最近做了个 lua 版的 nodejs。
https://github.com/zwh8800/lua-libuv
上个栗子:
local server = uv.createServer()
print(server)
local count = 1
server:listen('0.0.0.0', 8080,
function (socket, err)
if socket then
print(count .. ': ')
count = count + 1
print(socket)
socket:write('hello lua-uv\n')
socket:onData(
function(socket, nread, data)
if (nread >= 0) then
print('received: ' .. data)
if data == 'exit\n' then
socket:finish('bye')
end
else
print('error: ' .. socket .. ': ' .. data)
end
end
)
else
print('got nil' .. err)
end
end
)
uv.loop()