diff --git a/multi/init.lua b/multi/init.lua index 1a93d1c..5e87891 100644 --- a/multi/init.lua +++ b/multi/init.lua @@ -1197,7 +1197,7 @@ function thread:newFunctionBase(generator,holdme) end } end - local t = generator(...) --multi.getCurrentProcess():newThread("TempThread",func,...) + local t = generator(...) t.OnDeath(function(self,status,...) rets = {...} end) t.OnError(function(self,e) err = e end) if holdme then @@ -1209,6 +1209,9 @@ function thread:newFunctionBase(generator,holdme) OnReturn = multi:newConnection(), isTFunc = true, wait = wait, + getReturns = function() + return unpack(rets) + end, connect = function(f) local tempConn = multi:newConnection() t.OnDeath(function(self,status,...) if f then f(...) else tempConn:Fire(...) end end) diff --git a/multi/integration/lanesManager/init.lua b/multi/integration/lanesManager/init.lua index afb66ec..01afe62 100644 --- a/multi/integration/lanesManager/init.lua +++ b/multi/integration/lanesManager/init.lua @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] package.path = "?/init.lua;?.lua;" .. package.path -local multi, thread = require("multi"):init() -- get it all and have it on all lanes +multi, thread = require("multi"):init() -- get it all and have it on all lanes if multi.integration then -- This allows us to call the lanes manager from supporting modules without a hassle return { init = function() @@ -57,7 +57,6 @@ local GLOBAL,THREAD = require("multi.integration.lanesManager.threads").init(__G local count = 1 local started = false local livingThreads = {} -local threads = {} function THREAD:newFunction(func,holdme) return thread:newFunctionBase(function(...) @@ -69,7 +68,7 @@ function multi:newSystemThread(name, func, ...) multi.InitSystemThreadErrorHandler() local rand = math.random(1, 10000000) local return_linda = lanes.linda() - local c = {} + c = {} c.name = name c.Name = name c.Id = count @@ -94,12 +93,10 @@ function multi:newSystemThread(name, func, ...) local has_error = true return_linda:set("returns",{func(...)}) has_error = false - print("Thread ending") end)(...) count = count + 1 function c:kill() self.thread:cancel() - multi.print("Thread: '" .. self.name .. "' has been stopped!") self.alive = false end table.insert(multi.SystemThreads, c) @@ -108,7 +105,6 @@ function multi:newSystemThread(name, func, ...) GLOBAL["__THREADS__"] = livingThreads return c end - function multi.InitSystemThreadErrorHandler() if started == true then return diff --git a/test3.lua b/test3.lua index ac2e32f..13315a6 100644 --- a/test3.lua +++ b/test3.lua @@ -1,52 +1,19 @@ +package.path = "./?/init.lua;"..package.path local multi,thread = require("multi"):init() local GLOBAL,THREAD = require("multi.integration.threading"):init() function sleep(n) if n > 0 then os.execute("ping -n " .. tonumber(n+1) .. " localhost > NUL") end end --- local GLOBAL,THREAD = {},{}-- require("multi.integration.lanesManager.threads").init(__GlobalLinda,__SleepingLinda) --- local count = 1 --- local started = false --- local livingThreads = {} --- local threads = {} --- multi.SystemThreads = {} --- function multi:newSystemThread(name, func, ...) --- --multi.InitSystemThreadErrorHandler() --- local rand = math.random(1, 10000000) --- local return_linda = lanes.linda() --- local c = {} --- c.name = name --- c.Name = name --- c.Id = count --- c.loadString = {"base","package","os","io","math","table","string","coroutine"} --- livingThreads[count] = {true, name} --- c.returns = return_linda --- c.Type = "sthread" --- c.creationTime = os.clock() --- c.alive = true --- c.priority = THREAD.Priority_Normal --- c.thread = lanes.gen("*",func)(...) --- count = count + 1 --- function c:kill() --- self.thread:cancel() --- multi.print("Thread: '" .. self.name .. "' has been stopped!") --- self.alive = false --- end --- table.insert(multi.SystemThreads, c) --- c.OnDeath = multi:newConnection() --- c.OnError = multi:newConnection() --- GLOBAL["__THREADS__"] = livingThreads --- return c --- end -multi:newSystemThread("test",function() - print("Hello World!") +func = THREAD:newFunction(function(a,b,c) + print("Hello Thread!",a,b,c) + return 1,2,3 end) multi:newThread("Test thread",function() - while true do - thread.sleep(1) - print("...") - end + handler = func(4,5,6) + thread.hold(handler.OnReturn) + print("Function Done",handler.getReturns()) end) multi:mainloop() \ No newline at end of file