Skip to content

Commit f2ef5c4

Browse files
committed
Working ZeroBrane integration!
1 parent 5f3f1cd commit f2ef5c4

File tree

10 files changed

+3428
-0
lines changed

10 files changed

+3428
-0
lines changed

Data/Base.rte/AI/NativeHumanAI.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ end
8383
function NativeHumanAI:Update(Owner)
8484
self.Ctrl = Owner:GetController();
8585

86+
require('mobdebug').start()
87+
require('mobdebug').coro()
88+
8689
-- Our jetpack might have thrust balancing enabled, so update for our current mass
8790
if Owner.Jetpack then
8891
self.jetImpulseFactor = Owner.Jetpack:EstimateImpulse(false) * GetPPM() / TimerMan.DeltaTimeSecs;

Data/Base.rte/LuaIntegration/mobdebug/mobdebug.lua

Lines changed: 1670 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
-----------------------------------------------------------------------------
2+
-- LuaSocket helper module
3+
-- Author: Diego Nehab
4+
-----------------------------------------------------------------------------
5+
6+
-----------------------------------------------------------------------------
7+
-- Declare module and import dependencies
8+
-----------------------------------------------------------------------------
9+
local base = _G
10+
local string = require("string")
11+
local math = require("math")
12+
local socket = require("socket.core")
13+
14+
local _M = socket
15+
16+
-- this is needed in case this library is used when "socket.core" is loaded,
17+
-- but has an older version of luasocket that does not include `connect`.
18+
if not socket.connect then
19+
socket.connect = function (address, port, laddress, lport)
20+
local sock, err = socket.tcp()
21+
if not sock then return nil, err end
22+
if laddress then
23+
local res, err = sock:bind(laddress, lport, -1)
24+
if not res then return nil, err end
25+
end
26+
local res, err = sock:connect(address, port)
27+
if not res then return nil, err end
28+
return sock
29+
end
30+
end
31+
32+
-----------------------------------------------------------------------------
33+
-- Exported auxiliar functions
34+
-----------------------------------------------------------------------------
35+
function _M.connect4(address, port, laddress, lport)
36+
return socket.connect(address, port, laddress, lport, "inet")
37+
end
38+
39+
function _M.connect6(address, port, laddress, lport)
40+
return socket.connect(address, port, laddress, lport, "inet6")
41+
end
42+
43+
function _M.bind(host, port, backlog)
44+
if host == "*" then host = "0.0.0.0" end
45+
local addrinfo, err = socket.dns.getaddrinfo(host);
46+
if not addrinfo then return nil, err end
47+
local sock, res
48+
err = "no info on address"
49+
for i, alt in base.ipairs(addrinfo) do
50+
if alt.family == "inet" then
51+
sock, err = socket.tcp4()
52+
else
53+
sock, err = socket.tcp6()
54+
end
55+
if not sock then return nil, err end
56+
sock:setoption("reuseaddr", true)
57+
res, err = sock:bind(alt.addr, port)
58+
if not res then
59+
sock:close()
60+
else
61+
res, err = sock:listen(backlog)
62+
if not res then
63+
sock:close()
64+
else
65+
return sock
66+
end
67+
end
68+
end
69+
return nil, err
70+
end
71+
72+
_M.try = _M.newtry()
73+
74+
function _M.choose(table)
75+
return function(name, opt1, opt2)
76+
if base.type(name) ~= "string" then
77+
name, opt1, opt2 = "default", name, opt1
78+
end
79+
local f = table[name or "nil"]
80+
if not f then base.error("unknown key (".. base.tostring(name) ..")", 3)
81+
else return f(opt1, opt2) end
82+
end
83+
end
84+
85+
-----------------------------------------------------------------------------
86+
-- Socket sources and sinks, conforming to LTN12
87+
-----------------------------------------------------------------------------
88+
-- create namespaces inside LuaSocket namespace
89+
local sourcet, sinkt = {}, {}
90+
_M.sourcet = sourcet
91+
_M.sinkt = sinkt
92+
93+
_M.BLOCKSIZE = 2048
94+
95+
sinkt["close-when-done"] = function(sock)
96+
return base.setmetatable({
97+
getfd = function() return sock:getfd() end,
98+
dirty = function() return sock:dirty() end
99+
}, {
100+
__call = function(self, chunk, err)
101+
if not chunk then
102+
sock:close()
103+
return 1
104+
else return sock:send(chunk) end
105+
end
106+
})
107+
end
108+
109+
sinkt["keep-open"] = function(sock)
110+
return base.setmetatable({
111+
getfd = function() return sock:getfd() end,
112+
dirty = function() return sock:dirty() end
113+
}, {
114+
__call = function(self, chunk, err)
115+
if chunk then return sock:send(chunk)
116+
else return 1 end
117+
end
118+
})
119+
end
120+
121+
sinkt["default"] = sinkt["keep-open"]
122+
123+
_M.sink = _M.choose(sinkt)
124+
125+
sourcet["by-length"] = function(sock, length)
126+
return base.setmetatable({
127+
getfd = function() return sock:getfd() end,
128+
dirty = function() return sock:dirty() end
129+
}, {
130+
__call = function()
131+
if length <= 0 then return nil end
132+
local size = math.min(socket.BLOCKSIZE, length)
133+
local chunk, err = sock:receive(size)
134+
if err then return nil, err end
135+
length = length - string.len(chunk)
136+
return chunk
137+
end
138+
})
139+
end
140+
141+
sourcet["until-closed"] = function(sock)
142+
local done
143+
return base.setmetatable({
144+
getfd = function() return sock:getfd() end,
145+
dirty = function() return sock:dirty() end
146+
}, {
147+
__call = function()
148+
if done then return nil end
149+
local chunk, err, partial = sock:receive(socket.BLOCKSIZE)
150+
if not err then return chunk
151+
elseif err == "closed" then
152+
sock:close()
153+
done = 1
154+
return partial
155+
else return nil, err end
156+
end
157+
})
158+
end
159+
160+
161+
sourcet["default"] = sourcet["until-closed"]
162+
163+
_M.source = _M.choose(sourcet)
164+
165+
return _M

0 commit comments

Comments
 (0)