Syntax changes

This commit is contained in:
Ryan Ward 2022-04-19 18:45:14 -04:00
parent b0ab40d410
commit 3646a1a074

View File

@ -1422,7 +1422,9 @@ local switch = {
end, end,
function() end--none function() end--none
} }
setmetatable(switch,{__index=function() return function() end end}) setmetatable(switch,{__index=function() return function() end end})
local cmds = {-- ipart: t_hold, t_sleep, t_holdF, t_skip, t_holdW, t_yield, t_none <-- Order local cmds = {-- ipart: t_hold, t_sleep, t_holdF, t_skip, t_holdW, t_yield, t_none <-- Order
function(th,arg1,arg2,arg3) function(th,arg1,arg2,arg3)
th.func = arg1 th.func = arg1
@ -1558,6 +1560,7 @@ function multi:newService(func) -- Priority managed threads
local ap local ap
local task = thread.sleep local task = thread.sleep
local scheme = 1 local scheme = 1
function c.Start() function c.Start()
if not active then if not active then
time = self:newTimer() time = self:newTimer()
@ -1567,6 +1570,7 @@ function multi:newService(func) -- Priority managed threads
end end
return c return c
end end
local function process() local function process()
thread.hold(function() thread.hold(function()
return active return active
@ -1575,18 +1579,22 @@ function multi:newService(func) -- Priority managed threads
task(ap) task(ap)
return c return c
end end
local th = thread:newThread(function() local th = thread:newThread(function()
while true do while true do
process() process()
end end
end) end)
th.OnError = c.OnError -- use the threads onerror as our own th.OnError = c.OnError -- use the threads onerror as our own
function c.Destroy() function c.Destroy()
th:kill() th:kill()
c.Stop() c.Stop()
multi.setType(c,multi.DestroyedObj) multi.setType(c,multi.DestroyedObj)
return c return c
end end
function c:SetScheme(n) function c:SetScheme(n)
if type(self)=="number" then n = self end if type(self)=="number" then n = self end
scheme = n scheme = n
@ -1602,6 +1610,7 @@ function multi:newService(func) -- Priority managed threads
end end
return c return c
end end
function c.Stop() function c.Stop()
if active then if active then
c:OnStopped(c) c:OnStopped(c)
@ -1613,6 +1622,7 @@ function multi:newService(func) -- Priority managed threads
end end
return c return c
end end
function c.Pause() function c.Pause()
if active then if active then
time:Pause() time:Pause()
@ -1620,6 +1630,7 @@ function multi:newService(func) -- Priority managed threads
end end
return c return c
end end
function c.Resume() function c.Resume()
if not active then if not active then
time:Resume() time:Resume()
@ -1627,16 +1638,20 @@ function multi:newService(func) -- Priority managed threads
end end
return c return c
end end
function c.GetUpTime() function c.GetUpTime()
return time:Get() return time:Get()
end end
function c:SetPriority(pri) function c:SetPriority(pri)
if type(self)=="number" then pri = self end if type(self)=="number" then pri = self end
p = pri p = pri
c.SetScheme(scheme) c.SetScheme(scheme)
return c return c
end end
multi.create(multi,c) multi.create(multi,c)
return c return c
end end
@ -2039,18 +2054,22 @@ multi.SetName = multi.setName
-- Special Events -- Special Events
local _os = os.exit local _os = os.exit
function os.exit(n) function os.exit(n)
multi.OnExit:Fire(n or 0) multi.OnExit:Fire(n or 0)
_os(n) _os(n)
end end
multi.OnError=multi:newConnection() multi.OnError=multi:newConnection()
multi.OnPreLoad = multi:newConnection() multi.OnPreLoad = multi:newConnection()
multi.OnExit = multi:newConnection(nil,nil,true) multi.OnExit = multi:newConnection(nil,nil,true)
multi.m = {onexit = function() multi.OnExit:Fire() end} multi.m = {onexit = function() multi.OnExit:Fire() end}
if _VERSION >= "Lua 5.2" or jit then if _VERSION >= "Lua 5.2" or jit then
setmetatable(multi.m, {__gc = multi.m.onexit}) setmetatable(multi.m, {__gc = multi.m.onexit})
else else
multi.m.sentinel = newproxy(true) multi.m.sentinel = newproxy(true)
getmetatable(multi.m.sentinel).__gc = multi.m.onexit getmetatable(multi.m.sentinel).__gc = multi.m.onexit
end end
return multi return multi