V15.1.0 #26

Merged
rayaman merged 18 commits from V15.1.0 into master 2021-11-30 21:28:18 -05:00
2 changed files with 71 additions and 24 deletions
Showing only changes of commit bf517facd1 - Show all commits

View File

@ -33,12 +33,13 @@ end
multi.Version = "15.1.0" multi.Version = "15.1.0"
multi.stage = "stable" multi.stage = "stable"
multi.Name = "multi.root" multi.Name = "multi.root"
multi.NIL = {Type="NIL"}
multi.Mainloop = {} multi.Mainloop = {}
multi.Garbage = {} multi.Garbage = {}
multi.ender = {} multi.ender = {}
multi.Children = {} multi.Children = {}
multi.Active = true multi.Active = true
multi.Type = "mainprocess" multi.Type = "rootprocess"
multi.Rest = 0 multi.Rest = 0
multi._type = type multi._type = type
multi.queue = {} multi.queue = {}
@ -76,7 +77,6 @@ multi.threshold=256
multi.threstimed=.001 multi.threstimed=.001
function multi.init() function multi.init()
multi.NIL = {Type="NIL"}
return _G["$multi"].multi,_G["$multi"].thread return _G["$multi"].multi,_G["$multi"].thread
end end
@ -86,7 +86,7 @@ function multi.Stop()
end end
--Processor --Processor
local priorityTable = {[0]="Round-Robin",[1]="Just-Right",[2]="Top-heavy",[3]="Timed-Based-Balancer"} local priorityTable = {[0]="Round-Robin",[1]="Balanced",[2]="Top-Down",[3]="Timed-Based-Balancer"}
local ProcessName = {[true]="SubProcessor",[false]="MainProcessor"} local ProcessName = {[true]="SubProcessor",[false]="MainProcessor"}
function multi:getTasksDetails(t) function multi:getTasksDetails(t)
if t == "string" or not t then if t == "string" or not t then
@ -249,7 +249,7 @@ end
-- Timer stuff done -- Timer stuff done
multi.PausedObjects = {} multi.PausedObjects = {}
function multi:Pause() function multi:Pause()
if self.Type=='mainprocess' then if self.Type=='rootprocess' then
multi.print("You cannot pause the main process. Doing so will stop all methods and freeze your program! However if you still want to use multi:_Pause()") multi.print("You cannot pause the main process. Doing so will stop all methods and freeze your program! However if you still want to use multi:_Pause()")
else else
self.Active=false self.Active=false
@ -266,7 +266,7 @@ function multi:Pause()
end end
function multi:Resume() function multi:Resume()
if self.Type=='process' or self.Type=='mainprocess' then if self.Type=='process' or self.Type=='rootprocess' then
self.Active=true self.Active=true
local c=self:getChildren() local c=self:getChildren()
for i=1,#c do for i=1,#c do
@ -283,7 +283,7 @@ function multi:Resume()
end end
function multi:Destroy() function multi:Destroy()
if self.Type=='process' or self.Type=='mainprocess' then if self.Type=='process' or self.Type=='rootprocess' then
local c=self:getChildren() local c=self:getChildren()
for i=1,#c do for i=1,#c do
self.OnObjectDestroyed:Fire(c[i]) self.OnObjectDestroyed:Fire(c[i])
@ -324,7 +324,7 @@ end
--Constructors [CORE] --Constructors [CORE]
local _tid = 0 local _tid = 0
function multi:newBase(ins) function multi:newBase(ins)
if not(self.Type=='mainprocess' or self.Type=='process' or self.Type=='queue' or self.Type == 'sandbox') then error('Can only create an object on multi or an interface obj') return false end if not(self.Type=='rootprocess' or self.Type=='process' or self.Type=='queue' or self.Type == 'sandbox') then error('Can only create an object on multi or an interface obj') return false end
local c = {} local c = {}
if self.Type=='process' or self.Type=='queue' or self.Type=='sandbox' then if self.Type=='process' or self.Type=='queue' or self.Type=='sandbox' then
setmetatable(c, {__index = multi}) setmetatable(c, {__index = multi})
@ -1129,6 +1129,10 @@ local function cleanReturns(...)
end end
return unpack(returns,1,ind) return unpack(returns,1,ind)
end end
function thread.pushStatus(...)
local t = thread.getRunningThread()
t.statusconnector:Fire(...)
end
function thread:newFunction(func,holdme) function thread:newFunction(func,holdme)
local tfunc = {} local tfunc = {}
tfunc.Active = true tfunc.Active = true
@ -1138,6 +1142,9 @@ function thread:newFunction(func,holdme)
function tfunc:Resume() function tfunc:Resume()
self.Active = true self.Active = true
end end
function tfunc:holdMe(b)
holdme = b
end
local function noWait() local function noWait()
return nil, "Function is paused" return nil, "Function is paused"
end end
@ -1181,18 +1188,24 @@ function thread:newFunction(func,holdme)
return wait() return wait()
end end
local temp = { local temp = {
OnStatus = multi:newConnection(),
isTFunc = true, isTFunc = true,
wait = wait, wait = wait,
connect = function(f) connect = function(f)
t.OnDeath(function(self,status,...) f(...) end) local tempConn = multi:newConnection()
t.OnError(function(self,err) f(nil,err) end) t.OnDeath(function(self,status,...) if f then f(...) else tempConn:Fire(...) end end)
t.OnError(function(self,err) if f then f(nil,err) else tempConn:Fire(nil,err) end end)
return tempConn
end end
} }
t.linkedFunction = temp
t.statusconnector = temp.OnStatus
return temp return temp
end end
setmetatable(tfunc,tfunc) setmetatable(tfunc,tfunc)
return tfunc return tfunc
end end
-- A cross version way to set enviroments, not the same as fenv though -- A cross version way to set enviroments, not the same as fenv though
function multi.setEnv(func,env) function multi.setEnv(func,env)
local f = string.dump(func) local f = string.dump(func)

View File

@ -1,22 +1,56 @@
package.path = "./?/init.lua;"..package.path package.path = "./?/init.lua;"..package.path
multi,thread = require("multi"):init() multi,thread = require("multi"):init()
--GLOBAL,THREAD = require("multi.integration.threading"):init() -- Auto detects your enviroment and uses what's available
test = thread:newFunction(function(a,b) func = thread:newFunction(function()
local a = 0
while true do
a = a + 1
thread.sleep(1) thread.sleep(1)
return a,b thread.pushStatus(a)
if a == 10 then break end
end
return "Done"
end) end)
print(test(1,2).connect(function(...)
print(...) multi:newThread("test",function()
end)) local ret = func()
test:Pause() ret.OnStatus(function(test)
print(test(1,2).connect(function(...) print(test)
print(...) end)
end)) thread.hold(ret.connect())
test:Resume() print("Function Done!")
print(test(1,2).connect(function(...) os.exit()
print(...) end)
end))
--GLOBAL,THREAD = require("multi.integration.threading"):init() -- Auto detects your environment and uses what's available
-- func = thread:newFunction(function()
-- thread.sleep(3)
-- print("Hello World!")
-- return true
-- end,true) -- set holdme to true
-- func:holdMe(false) -- reset holdme to false
-- print("Calling func...")
-- print(func())
-- test = thread:newFunction(function(a,b)
-- thread.sleep(1)
-- return a,b
-- end)
-- print(test(1,2).connect(function(...)
-- print(...)
-- end))
-- test:Pause()
-- print(test(1,2).connect(function(...)
-- print(...)
-- end))
-- test:Resume()
-- print(test(1,2).connect(function(...)
-- print(...)
-- end))
-- test = thread:newFunction(function() -- test = thread:newFunction(function()
-- return 1,2,nil,3,4,5,6,7,8,9 -- return 1,2,nil,3,4,5,6,7,8,9