最近做了个小玩意

lua 版的 nodejs

都听说过 nodejs 吧,最近做了个 lua 版的 nodejs。

https://github.com/zwh8800/lua-libuv

上个栗子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()

Proudly powered by Hexo and Theme by Hacker
© 2021 wastecat