diff --git a/lanesintergratetest2.lua b/lanesintergratetest2.lua new file mode 100644 index 0000000..f727a3b --- /dev/null +++ b/lanesintergratetest2.lua @@ -0,0 +1,36 @@ +package.path="?/init.lua;?.lua;"..package.path +local GLOBAL,sThread=require("multi.intergration.lanesManager").init() +multi:newSystemThread("test1",function() -- spawns a thread in another lua process + require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though + multi:benchMark(1,nil,"Thread 1"):OnBench(function(self,c) GLOBAL["T1"]=c multi:Stop() end) + multi:mainloop() +end) +multi:newSystemThread("test2",function() -- spawns a thread in another lua process + require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though + multi:benchMark(1,nil,"Thread 2"):OnBench(function(self,c) GLOBAL["T2"]=c multi:Stop() end) + multi:mainloop() +end) +multi:newSystemThread("test3",function() -- spawns a thread in another lua process + require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though + multi:benchMark(1,nil,"Thread 3"):OnBench(function(self,c) GLOBAL["T3"]=c multi:Stop() end) + multi:mainloop() +end) +multi:newSystemThread("test4",function() -- spawns a thread in another lua process + require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though + multi:benchMark(1,nil,"Thread 4"):OnBench(function(self,c) GLOBAL["T4"]=c multi:Stop() end) + multi:mainloop() +end) +multi:newSystemThread("test5",function() -- spawns a thread in another lua process + require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though + multi:benchMark(1,nil,"Thread 5"):OnBench(function(self,c) GLOBAL["T5"]=c multi:Stop() end) + multi:mainloop() +end) +multi:newSystemThread("test6",function() -- spawns a thread in another lua process + require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though + multi:benchMark(1,nil,"Thread 6"):OnBench(function(self,c) GLOBAL["T6"]=c multi:Stop() end) + multi:mainloop() +end) +multi:newSystemThread("test6",function() -- spawns a thread in another lua process + print("Bench: ",sThread.waitFor("T1")+sThread.waitFor("T2")+sThread.waitFor("T3")+sThread.waitFor("T4")+sThread.waitFor("T5")+sThread.waitFor("T6")) +end) +multi:mainloop() diff --git a/multi/alarm.lua b/multi/alarm.lua index dd0c74d..d14aac6 100644 --- a/multi/alarm.lua +++ b/multi/alarm.lua @@ -1,42 +1 @@ require("multi") -function multi:newAlarm(set) - local c=self:newBase() - c.Type='alarm' - c.Priority=self.Priority_Low - c.timer=self:newTimer() - c.set=set or 0 - function c:tofile(path) - local m=bin.new() - m:addBlock(self.Type) - m:addBlock(self.set) - m:addBlock(self.Active) - m:tofile(path) - end - function c:Act() - if self.timer:Get()>=self.set then - self:Pause() - self.Active=false - for i=1,#self.func do - self.func[i](self) - end - end - end - function c:Resume() - self.Parent.Resume(self) - self.timer:Resume() - end - function c:Reset(n) - if n then self.set=n end - self:Resume() - self.timer:Reset() - end - function c:OnRing(func) - table.insert(self.func,func) - end - function c:Pause() - self.timer:Pause() - self.Parent.Pause(self) - end - self:create(c) - return c -end diff --git a/multi/init.lua b/multi/init.lua index f0d0461..6783b3a 100644 --- a/multi/init.lua +++ b/multi/init.lua @@ -22,7 +22,7 @@ function print(...) end end multi = {} -multi.Version={1,7,1} +multi.Version={1,7,2} multi.stage='stable' multi.__index = multi multi.Mainloop={} @@ -319,7 +319,7 @@ function multi:fromfile(path,int) return test2 end function multi:benchMark(sec,p,pt) - local temp=self:newLoop(function(t,self) + local temp=self:newLoop(function(self,t) if self.clock()-self.init>self.sec then if pt then print(pt.." "..self.c.." Steps in "..sec.." second(s)!") @@ -671,7 +671,7 @@ function multi:newProcess(file) c.Jobs={} c.queue={} c.jobUS=2 - c.l=self:newLoop(function(dt) c:uManager(dt) end) + c.l=self:newLoop(function(self,dt) c:uManager(dt) end) c.l:Pause() function c:getController() return c.l @@ -936,7 +936,7 @@ function multi:mainloop() while self.Active do self:Do_Order() end - print("Did you call multi:Stop()? This method should not be used when using multi:mainloop() unless of course you wanted to stop it! you can restart the multi, by using multi:reboot() and calling multi:mainloop() again or by using multi:uManager()") + --print("Did you call multi:Stop()? This method should not be used when using multi:mainloop() unless of course you wanted to stop it! you can restart the multi, by using multi:reboot() and calling multi:mainloop() again or by using multi:uManager()") end function multi._tFunc(self,dt) for i=1,#self.Tasks do @@ -1005,3 +1005,90 @@ function multi:newEvent(task) self:create(c) return c end +function multi:newUpdater(skip) + local c=self:newBase() + c.Type='updater' + c.pos=1 + c.skip=skip or 1 + function c:Act() + if self.pos>=self.skip then + self.pos=0 + for i=1,#self.func do + self.func[i](self) + end + end + self.pos=self.pos+1 + end + function c:setSkip(n) + self.skip=n + end + c.OnUpdate=self.OnMainConnect + self:create(c) + return c +end +function multi:newAlarm(set) + local c=self:newBase() + c.Type='alarm' + c.Priority=self.Priority_Low + c.timer=self:newTimer() + c.set=set or 0 + function c:tofile(path) + local m=bin.new() + m:addBlock(self.Type) + m:addBlock(self.set) + m:addBlock(self.Active) + m:tofile(path) + end + function c:Act() + if self.timer:Get()>=self.set then + self:Pause() + self.Active=false + for i=1,#self.func do + self.func[i](self) + end + end + end + function c:Resume() + self.Parent.Resume(self) + self.timer:Resume() + end + function c:Reset(n) + if n then self.set=n end + self:Resume() + self.timer:Reset() + end + function c:OnRing(func) + table.insert(self.func,func) + end + function c:Pause() + self.timer:Pause() + self.Parent.Pause(self) + end + self:create(c) + return c +end +function multi:newLoop(func) + local c=self:newBase() + c.Type='loop' + c.Start=self.clock() + if func then + c.func={func} + end + function c:tofile(path) + local m=bin.new() + m:addBlock(self.Type) + m:addBlock(self.func) + m:addBlock(self.Active) + m:tofile(path) + end + function c:Act() + for i=1,#self.func do + self.func[i](self,self.Parent.clock()-self.Start) + end + end + function c:OnLoop(func) + table.insert(self.func,func) + end + self:create(c) + return c +end diff --git a/multi/intergration/lanesManager.lua b/multi/intergration/lanesManager.lua index 68ef7ca..650abad 100644 --- a/multi/intergration/lanesManager.lua +++ b/multi/intergration/lanesManager.lua @@ -91,7 +91,7 @@ function multi:newSystemThread(name,func) c.status:OnUpdate(function(self) local v,err,t=self.link.thread:join(.001) if err then - print("Error in thread: '"..self.link.name.."' <"..err..">",t) + print("Error in thread: '"..self.link.name.."' <"..err..">") self:Destroy() end end) diff --git a/multi/loop.lua b/multi/loop.lua index 524b8e1..d14aac6 100644 --- a/multi/loop.lua +++ b/multi/loop.lua @@ -1,26 +1 @@ require("multi") -function multi:newLoop(func) - local c=self:newBase() - c.Type='loop' - c.Start=self.clock() - if func then - c.func={func} - end - function c:tofile(path) - local m=bin.new() - m:addBlock(self.Type) - m:addBlock(self.func) - m:addBlock(self.Active) - m:tofile(path) - end - function c:Act() - for i=1,#self.func do - self.func[i](self,self.Parent.clock()-self.Start) - end - end - function c:OnLoop(func) - table.insert(self.func,func) - end - self:create(c) - return c -end diff --git a/multi/updater.lua b/multi/updater.lua index 9214f78..d14aac6 100644 --- a/multi/updater.lua +++ b/multi/updater.lua @@ -1,22 +1 @@ require("multi") -function multi:newUpdater(skip) - local c=self:newBase() - c.Type='updater' - c.pos=1 - c.skip=skip or 1 - function c:Act() - if self.pos>=self.skip then - self.pos=0 - for i=1,#self.func do - self.func[i](self) - end - end - self.pos=self.pos+1 - end - function c:setSkip(n) - self.skip=n - end - c.OnUpdate=self.OnMainConnect - self:create(c) - return c -end