V15.3.0 #46
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2021 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
Table of contents
|
Table of contents
|
||||||
---
|
---
|
||||||
[Update 15.1.0 - Hold the thread!](#update-1510---hold-the-thread)</br>[Update 15.0.0 - The art of faking it](#update-1500---the-art-of-faking-it)</br>[Update 14.2.0 - Bloatware Removed](#update-1420---bloatware-removed)</br>[Update 14.1.0 - A whole new world of possibilities](#update-1410---a-whole-new-world-of-possibilities)</br>[Update 14.0.0 - Consistency, Additions and Stability](#update-1400---consistency-additions-and-stability)</br>[Update 13.1.0 - Bug fixes and features added](#update-1310---bug-fixes-and-features-added)</br>[Update 13.0.0 - Added some documentation, and some new features too check it out!](#update-1300---added-some-documentation-and-some-new-features-too-check-it-out)</br>[Update 12.2.2 - Time for some more bug fixes!](#update-1222---time-for-some-more-bug-fixes)</br>[Update 12.2.1 - Time for some bug fixes!](#update-1221---time-for-some-bug-fixes)</br>[Update 12.2.0 - The chains of binding](#update-1220---the-chains-of-binding)</br>[Update 12.1.0 - Threads just can't hold on anymore](#update-1210---threads-just-cant-hold-on-anymore)</br>[Update: 12.0.0 - Big update (Lots of additions some changes)](#update-1200---big-update-lots-of-additions-some-changes)</br>[Update: 1.11.1 - Small Clarification on Love](#update-1111---small-clarification-on-love)</br>[Update: 1.11.0](#update-1110)</br>[Update: 1.10.0](#update-1100)</br>[Update: 1.9.2](#update-192)</br>[Update: 1.9.1 - Threads can now argue](#update-191---threads-can-now-argue)</br>[Update: 1.9.0](#update-190)</br>[Update: 1.8.7](#update-187)</br>[Update: 1.8.6](#update-186)</br>[Update: 1.8.5](#update-185)</br>[Update: 1.8.4](#update-184)</br>[Update: 1.8.3 - Mainloop recieves some needed overhauling](#update-183---mainloop-recieves-some-needed-overhauling)</br>[Update: 1.8.2](#update-182)</br>[Update: 1.8.1](#update-181)</br>[Update: 1.7.6](#update-176)</br>[Update: 1.7.5](#update-175)</br>[Update: 1.7.4](#update-174)</br>[Update: 1.7.3](#update-173)</br>[Update: 1.7.2](#update-172)</br>[Update: 1.7.1 - Bug Fixes Only](#update-171---bug-fixes-only)</br>[Update: 1.7.0 - Threading the systems](#update-170---threading-the-systems)</br>[Update: 1.6.0](#update-160)</br>[Update: 1.5.0](#update-150)</br>[Update: 1.4.1 (4/10/2017) - First Public release of the library](#update-141-4102017---first-public-release-of-the-library)</br>[Update: 1.4.0 (3/20/2017)](#update-140-3202017)</br>[Update: 1.3.0 (1/29/2017)](#update-130-1292017)</br>[Update: 1.2.0 (12.31.2016)](#update-120-12312016)</br>[Update: 1.1.0](#update-110)</br>[Update: 1.0.0](#update-100)</br>[Update: 0.6.3](#update-063)</br>[Update: 0.6.2](#update-062)</br>[Update: 0.6.1-6](#update-061-6)</br>[Update: 0.5.1-6](#update-051-6)</br>[Update: 0.4.1](#update-041)</br>[Update: 0.3.0 - The update that started it all](#update-030---the-update-that-started-it-all)</br>[Update: EventManager 2.0.0](#update-eventmanager-200)</br>[Update: EventManager 1.2.0](#update-eventmanager-120)</br>[Update: EventManager 1.1.0](#update-eventmanager-110)</br>[Update: EventManager 1.0.0 - Error checking](#update-eventmanager-100---error-checking)</br>[Version: EventManager 0.0.1 - In The Beginning things were very different](#version-eventmanager-001---in-the-beginning-things-were-very-different)
|
[Update 15.2.0 - Upgrade Complete](#update-1520---upgrade-complete)</br>[Update 15.1.0 - Hold the thread!](#update-1510---hold-the-thread)</br>[Update 15.0.0 - The art of faking it](#update-1500---the-art-of-faking-it)</br>[Update 14.2.0 - Bloatware Removed](#update-1420---bloatware-removed)</br>[Update 14.1.0 - A whole new world of possibilities](#update-1410---a-whole-new-world-of-possibilities)</br>[Update 14.0.0 - Consistency, Additions and Stability](#update-1400---consistency-additions-and-stability)</br>[Update 13.1.0 - Bug fixes and features added](#update-1310---bug-fixes-and-features-added)</br>[Update 13.0.0 - Added some documentation, and some new features too check it out!](#update-1300---added-some-documentation-and-some-new-features-too-check-it-out)</br>[Update 12.2.2 - Time for some more bug fixes!](#update-1222---time-for-some-more-bug-fixes)</br>[Update 12.2.1 - Time for some bug fixes!](#update-1221---time-for-some-bug-fixes)</br>[Update 12.2.0 - The chains of binding](#update-1220---the-chains-of-binding)</br>[Update 12.1.0 - Threads just can't hold on anymore](#update-1210---threads-just-cant-hold-on-anymore)</br>[Update: 12.0.0 - Big update (Lots of additions some changes)](#update-1200---big-update-lots-of-additions-some-changes)</br>[Update: 1.11.1 - Small Clarification on Love](#update-1111---small-clarification-on-love)</br>[Update: 1.11.0](#update-1110)</br>[Update: 1.10.0](#update-1100)</br>[Update: 1.9.2](#update-192)</br>[Update: 1.9.1 - Threads can now argue](#update-191---threads-can-now-argue)</br>[Update: 1.9.0](#update-190)</br>[Update: 1.8.7](#update-187)</br>[Update: 1.8.6](#update-186)</br>[Update: 1.8.5](#update-185)</br>[Update: 1.8.4](#update-184)</br>[Update: 1.8.3 - Mainloop recieves some needed overhauling](#update-183---mainloop-recieves-some-needed-overhauling)</br>[Update: 1.8.2](#update-182)</br>[Update: 1.8.1](#update-181)</br>[Update: 1.7.6](#update-176)</br>[Update: 1.7.5](#update-175)</br>[Update: 1.7.4](#update-174)</br>[Update: 1.7.3](#update-173)</br>[Update: 1.7.2](#update-172)</br>[Update: 1.7.1 - Bug Fixes Only](#update-171---bug-fixes-only)</br>[Update: 1.7.0 - Threading the systems](#update-170---threading-the-systems)</br>[Update: 1.6.0](#update-160)</br>[Update: 1.5.0](#update-150)</br>[Update: 1.4.1 (4/10/2017) - First Public release of the library](#update-141-4102017---first-public-release-of-the-library)</br>[Update: 1.4.0 (3/20/2017)](#update-140-3202017)</br>[Update: 1.3.0 (1/29/2017)](#update-130-1292017)</br>[Update: 1.2.0 (12.31.2016)](#update-120-12312016)</br>[Update: 1.1.0](#update-110)</br>[Update: 1.0.0](#update-100)</br>[Update: 0.6.3](#update-063)</br>[Update: 0.6.2](#update-062)</br>[Update: 0.6.1-6](#update-061-6)</br>[Update: 0.5.1-6](#update-051-6)</br>[Update: 0.4.1](#update-041)</br>[Update: 0.3.0 - The update that started it all](#update-030---the-update-that-started-it-all)</br>[Update: EventManager 2.0.0](#update-eventmanager-200)</br>[Update: EventManager 1.2.0](#update-eventmanager-120)</br>[Update: EventManager 1.1.0](#update-eventmanager-110)</br>[Update: EventManager 1.0.0 - Error checking](#update-eventmanager-100---error-checking)</br>[Version: EventManager 0.0.1 - In The Beginning things were very different](#version-eventmanager-001---in-the-beginning-things-were-very-different)
|
||||||
|
|
||||||
# Update 15.2.0 - Upgrade Complete
|
# Update 15.2.0 - Upgrade Complete
|
||||||
|
|
||||||
@ -26,7 +26,6 @@ Added:
|
|||||||
|
|
||||||
Changed:
|
Changed:
|
||||||
---
|
---
|
||||||
|
|
||||||
- Connection Objects now pass on the parent object if created on a multiobj. This was to allow chaining to work properly with the new update
|
- Connection Objects now pass on the parent object if created on a multiobj. This was to allow chaining to work properly with the new update
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
@ -76,7 +75,6 @@ Changed:
|
|||||||
|
|
||||||
### Developer Note:
|
### Developer Note:
|
||||||
|
|
||||||
|
|
||||||
Connections are some of the most complex objects that this library has outside of some of the system threaded stuff. I tend to add features to connection objects quite often. Just last update connections can be "added" together creating a temp connection that only triggers when all of the added connections got triggered as well. Thinking about the possibilities this could give developers using the library I had to changed the base classes to use connections.
|
Connections are some of the most complex objects that this library has outside of some of the system threaded stuff. I tend to add features to connection objects quite often. Just last update connections can be "added" together creating a temp connection that only triggers when all of the added connections got triggered as well. Thinking about the possibilities this could give developers using the library I had to changed the base classes to use connections.
|
||||||
|
|
||||||
The best part about this is that connections allow for greater control over an object's events. You can add and remove events that have been connected to as well as a lot of other things. Reference the documentation [here](./Documentation.md#non-actor-connections)
|
The best part about this is that connections allow for greater control over an object's events. You can add and remove events that have been connected to as well as a lot of other things. Reference the documentation [here](./Documentation.md#non-actor-connections)
|
||||||
@ -84,6 +82,7 @@ The best part about this is that connections allow for greater control over an o
|
|||||||
|
|
||||||
Removed:
|
Removed:
|
||||||
---
|
---
|
||||||
|
Nothing
|
||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
---
|
---
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -1148,7 +1148,8 @@ function thread.pushStatus(...)
|
|||||||
local t = thread.getRunningThread()
|
local t = thread.getRunningThread()
|
||||||
t.statusconnector:Fire(...)
|
t.statusconnector:Fire(...)
|
||||||
end
|
end
|
||||||
function thread:newFunction(func,holdme)
|
function thread:newFunctionBase(generator,holdme)
|
||||||
|
return function()
|
||||||
local tfunc = {}
|
local tfunc = {}
|
||||||
tfunc.Active = true
|
tfunc.Active = true
|
||||||
function tfunc:Pause()
|
function tfunc:Pause()
|
||||||
@ -1196,7 +1197,7 @@ function thread:newFunction(func,holdme)
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
local t = multi.getCurrentProcess():newThread("TempThread",func,...)
|
local t = generator(...) --multi.getCurrentProcess():newThread("TempThread",func,...)
|
||||||
t.OnDeath(function(self,status,...) rets = {...} end)
|
t.OnDeath(function(self,status,...) rets = {...} end)
|
||||||
t.OnError(function(self,e) err = e end)
|
t.OnError(function(self,e) err = e end)
|
||||||
if holdme then
|
if holdme then
|
||||||
@ -1223,6 +1224,12 @@ function thread:newFunction(func,holdme)
|
|||||||
end
|
end
|
||||||
setmetatable(tfunc,tfunc)
|
setmetatable(tfunc,tfunc)
|
||||||
return tfunc
|
return tfunc
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function thread:newFunction(func,holdme)
|
||||||
|
return thread:newFunctionBase(function(...)
|
||||||
|
return multi.getCurrentProcess():newThread("TempThread",func,...)
|
||||||
|
end,holdme)()
|
||||||
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
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
]]
|
]]
|
||||||
package.path = "?/init.lua;?.lua;" .. package.path
|
package.path = "?/init.lua;?.lua;" .. package.path
|
||||||
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
|
if multi.integration then -- This allows us to call the lanes manager from supporting modules without a hassle
|
||||||
return {
|
return {
|
||||||
init = function()
|
init = function()
|
||||||
@ -31,15 +31,18 @@ if multi.integration then -- This allows us to call the lanes manager from suppo
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
-- Step 1 get lanes
|
-- Step 1 get lanes
|
||||||
lanes = require("lanes").configure()
|
lanes = require("lanes").configure({allocator="protected",verbose_errors=""})
|
||||||
multi.SystemThreads = {}
|
multi.SystemThreads = {}
|
||||||
multi.isMainThread = true
|
multi.isMainThread = true
|
||||||
|
|
||||||
function multi:canSystemThread()
|
function multi:canSystemThread()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function multi:getPlatform()
|
function multi:getPlatform()
|
||||||
return "lanes"
|
return "lanes"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Step 2 set up the Linda objects
|
-- Step 2 set up the Linda objects
|
||||||
local __GlobalLinda = lanes.linda() -- handles global stuff
|
local __GlobalLinda = lanes.linda() -- handles global stuff
|
||||||
local __SleepingLinda = lanes.linda() -- handles sleeping stuff
|
local __SleepingLinda = lanes.linda() -- handles sleeping stuff
|
||||||
@ -50,118 +53,50 @@ multi:newLoop(function()
|
|||||||
print(unpack(data))
|
print(unpack(data))
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
local GLOBAL,THREAD = require("multi.integration.lanesManager.threads").init(__GlobalLinda,__SleepingLinda)
|
local GLOBAL,THREAD = {},{}-- require("multi.integration.lanesManager.threads").init(__GlobalLinda,__SleepingLinda)
|
||||||
local threads = {}
|
|
||||||
local count = 1
|
local count = 1
|
||||||
local started = false
|
local started = false
|
||||||
local livingThreads = {}
|
local livingThreads = {}
|
||||||
|
local threads = {}
|
||||||
|
|
||||||
function THREAD:newFunction(func,holdme)
|
function THREAD:newFunction(func,holdme)
|
||||||
local tfunc = {}
|
return thread:newFunctionBase(function(...)
|
||||||
tfunc.Active = true
|
return multi:newSystemThread("TempSystemThread",func,...)
|
||||||
function tfunc:Pause()
|
end,holdme)()
|
||||||
self.Active = false
|
|
||||||
end
|
|
||||||
function tfunc:Resume()
|
|
||||||
self.Active = true
|
|
||||||
end
|
|
||||||
function tfunc:holdMe(b)
|
|
||||||
holdme = b
|
|
||||||
end
|
|
||||||
local function noWait()
|
|
||||||
return nil, "Function is paused"
|
|
||||||
end
|
|
||||||
local rets, err
|
|
||||||
local function wait(no)
|
|
||||||
if thread.isThread() and not (no) then
|
|
||||||
return multi.hold(function()
|
|
||||||
if err then
|
|
||||||
return nil, err
|
|
||||||
elseif rets then
|
|
||||||
return unpack(rets)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
else
|
|
||||||
while not rets and not err do
|
|
||||||
multi.scheduler:Act()
|
|
||||||
end
|
|
||||||
if err then
|
|
||||||
return nil,err
|
|
||||||
end
|
|
||||||
return unpack(rets)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
tfunc.__call = function(t,...)
|
|
||||||
if not t.Active then
|
|
||||||
if holdme then
|
|
||||||
return nil, "Function is paused"
|
|
||||||
end
|
|
||||||
return {
|
|
||||||
isTFunc = true,
|
|
||||||
wait = noWait,
|
|
||||||
connect = function(f)
|
|
||||||
f(nil,"Function is paused")
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
|
||||||
local t = multi:newSystemThread("SystemThreadedFunction",func,...)
|
|
||||||
t.OnDeath(function(self,...) rets = {...} end)
|
|
||||||
t.OnError(function(self,e) err = e end)
|
|
||||||
if holdme then
|
|
||||||
return wait()
|
|
||||||
end
|
|
||||||
local temp = {
|
|
||||||
OnStatus = multi:newConnection(),
|
|
||||||
OnError = multi:newConnection(),
|
|
||||||
OnReturn = multi:newConnection(),
|
|
||||||
isTFunc = true,
|
|
||||||
wait = wait,
|
|
||||||
connect = function(f)
|
|
||||||
local tempConn = multi:newConnection()
|
|
||||||
t.OnDeath(function(self,...) 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
|
|
||||||
}
|
|
||||||
t.OnDeath(function(self,...) temp.OnReturn:Fire(...) end)
|
|
||||||
t.OnError(function(self,err) temp.OnError:Fire(err) end)
|
|
||||||
t.linkedFunction = temp
|
|
||||||
t.statusconnector = temp.OnStatus
|
|
||||||
return temp
|
|
||||||
end
|
|
||||||
setmetatable(tfunc,tfunc)
|
|
||||||
return tfunc
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function multi:newSystemThread(name, func, ...)
|
function multi:newSystemThread(name, func, ...)
|
||||||
multi.InitSystemThreadErrorHandler()
|
--multi.InitSystemThreadErrorHandler()
|
||||||
rand = math.random(1, 10000000)
|
local rand = math.random(1, 10000000)
|
||||||
|
local return_linda = lanes.linda()
|
||||||
local c = {}
|
local c = {}
|
||||||
local __self = c
|
|
||||||
c.name = name
|
c.name = name
|
||||||
c.Name = name
|
c.Name = name
|
||||||
c.Id = count
|
c.Id = count
|
||||||
c.loadString = {"base","package","os","io","math","table","string","coroutine"}
|
c.loadString = {"base","package","os","io","math","table","string","coroutine"}
|
||||||
livingThreads[count] = {true, name}
|
livingThreads[count] = {true, name}
|
||||||
|
c.returns = return_linda
|
||||||
c.Type = "sthread"
|
c.Type = "sthread"
|
||||||
c.creationTime = os.clock()
|
c.creationTime = os.clock()
|
||||||
c.alive = true
|
c.alive = true
|
||||||
c.priority = THREAD.Priority_Normal
|
c.priority = THREAD.Priority_Normal
|
||||||
local args = {...}
|
c.thread = lanes.gen("*",
|
||||||
multi:newThread(function()
|
|
||||||
c.thread = lanes.gen(table.concat(c.loadString,","),
|
|
||||||
{
|
{
|
||||||
globals={ -- Set up some globals
|
globals={ -- Set up some globals
|
||||||
THREAD_NAME=name,
|
THREAD_NAME = name,
|
||||||
THREAD_ID=count,
|
THREAD_ID = count,
|
||||||
THREAD = THREAD,
|
THREAD = THREAD,
|
||||||
GLOBAL = GLOBAL,
|
GLOBAL = GLOBAL,
|
||||||
_Console = __ConsoleLinda
|
_Console = __ConsoleLinda
|
||||||
},
|
},
|
||||||
priority=c.priority
|
priority=c.priority
|
||||||
},func)(unpack(args))
|
},function(...)
|
||||||
thread.kill()
|
local has_error = true
|
||||||
end)
|
return_linda:set("returns",{func(...)})
|
||||||
|
has_error = false
|
||||||
|
--error("thread killed")
|
||||||
|
print("Thread ending")
|
||||||
|
end)(...)
|
||||||
count = count + 1
|
count = count + 1
|
||||||
function c:kill()
|
function c:kill()
|
||||||
self.thread:cancel()
|
self.thread:cancel()
|
||||||
@ -171,61 +106,56 @@ function multi:newSystemThread(name, func, ...)
|
|||||||
table.insert(multi.SystemThreads, c)
|
table.insert(multi.SystemThreads, c)
|
||||||
c.OnDeath = multi:newConnection()
|
c.OnDeath = multi:newConnection()
|
||||||
c.OnError = multi:newConnection()
|
c.OnError = multi:newConnection()
|
||||||
GLOBAL["__THREADS__"] = livingThreads
|
--GLOBAL["__THREADS__"] = livingThreads
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
|
|
||||||
local function detectLuaError(str)
|
|
||||||
return type(str)=="string" and str:match("%.lua:%d*:")
|
|
||||||
end
|
|
||||||
|
|
||||||
local function tableLen(tab)
|
|
||||||
local len = 0
|
|
||||||
for i,v in pairs(tab) do
|
|
||||||
len = len + 1
|
|
||||||
end
|
|
||||||
return len
|
|
||||||
end
|
|
||||||
|
|
||||||
function multi.InitSystemThreadErrorHandler()
|
function multi.InitSystemThreadErrorHandler()
|
||||||
if started == true then
|
if started == true then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
started = true
|
started = true
|
||||||
multi:newThread("ThreadErrorHandler",function()
|
multi:newThread("SystemThreadScheduler",function()
|
||||||
local threads = multi.SystemThreads
|
local threads = multi.SystemThreads
|
||||||
while true do
|
while true do
|
||||||
thread.sleep(.1) -- switching states often takes a huge hit on performance. half a second to tell me there is an error is good enough.
|
thread.sleep(.01) -- switching states often takes a huge hit on performance. half a second to tell me there is an error is good enough.
|
||||||
for i = #threads, 1, -1 do
|
for i = #threads, 1, -1 do
|
||||||
local _,data = pcall(function()
|
local status = threads[i].thread.status
|
||||||
return {threads[i].thread:join(1)}
|
local temp = threads[i]
|
||||||
end)
|
if status == "done" or temp.returns:get("returns") then
|
||||||
local v, err, t = data[1],data[2],data[3]
|
livingThreads[temp.Id] = {false, temp.Name}
|
||||||
if detectLuaError(err) then
|
temp.alive = false
|
||||||
if err:find("Thread was killed!\1") then
|
temp.OnDeath:Fire(temp,nil,unpack(({temp.returns:receive(0, "returns")})[2]))
|
||||||
livingThreads[threads[i].Id] = {false, threads[i].Name}
|
--GLOBAL["__THREADS__"] = livingThreads
|
||||||
threads[i].alive = false
|
--print(temp.thread:cancel(10,true))
|
||||||
threads[i].OnDeath:Fire(threads[i],nil,"Thread was killed!")
|
|
||||||
GLOBAL["__THREADS__"] = livingThreads
|
|
||||||
table.remove(threads, i)
|
table.remove(threads, i)
|
||||||
else
|
elseif status == "running" then
|
||||||
threads[i].OnError:Fire(threads[i], err, "Error in systemThread: '" .. threads[i].name .. "' <" .. err .. ">")
|
--
|
||||||
threads[i].alive = false
|
elseif status == "waiting" then
|
||||||
livingThreads[threads[i].Id] = {false, threads[i].Name}
|
--
|
||||||
GLOBAL["__THREADS__"] = livingThreads
|
elseif status == "error" then
|
||||||
|
livingThreads[temp.Id] = {false, temp.Name}
|
||||||
|
temp.alive = false
|
||||||
|
temp.OnError:Fire(temp,nil,unpack(temp.returns:receive(0,"returns")))
|
||||||
|
--GLOBAL["__THREADS__"] = livingThreads
|
||||||
table.remove(threads, i)
|
table.remove(threads, i)
|
||||||
end
|
elseif status == "cancelled" then
|
||||||
elseif tableLen(data)>0 then
|
livingThreads[temp.Id] = {false, temp.Name}
|
||||||
livingThreads[threads[i].Id] = {false, threads[i].Name}
|
temp.alive = false
|
||||||
threads[i].alive = false
|
temp.OnError:Fire(temp,nil,"thread_cancelled")
|
||||||
threads[i].OnDeath:Fire(threads[i],unpack(data))
|
--GLOBAL["__THREADS__"] = livingThreads
|
||||||
GLOBAL["__THREADS__"] = livingThreads
|
table.remove(threads, i)
|
||||||
|
elseif status == "killed" then
|
||||||
|
livingThreads[temp.Id] = {false, temp.Name}
|
||||||
|
temp.alive = false
|
||||||
|
temp.OnError:Fire(temp,nil,"thread_killed")
|
||||||
|
--GLOBAL["__THREADS__"] = livingThreads
|
||||||
table.remove(threads, i)
|
table.remove(threads, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end).OnError(function(...)
|
end).OnError(function(...)
|
||||||
print("Error!",...)
|
print(...)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
multi.print("Integrated Lanes!")
|
multi.print("Integrated Lanes!")
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
Copyright (c) 2022 Ryan Ward
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
17
test3.lua
Normal file
17
test3.lua
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
lanes = require("lanes").configure({allocator="protected",verbose_errors=""})
|
||||||
|
local multi,thread = require("multi"):init()
|
||||||
|
function sleep(n)
|
||||||
|
if n > 0 then os.execute("ping -n " .. tonumber(n+1) .. " localhost > NUL") end
|
||||||
|
end
|
||||||
|
|
||||||
|
lanes.gen("*",function()
|
||||||
|
print("Hello!")
|
||||||
|
end)()
|
||||||
|
|
||||||
|
multi:newThread("Test thread",function()
|
||||||
|
while true do
|
||||||
|
thread.sleep(1)
|
||||||
|
print("...")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
multi:mainloop()
|
||||||
Loading…
x
Reference in New Issue
Block a user