Changed the structure of the code
This commit is contained in:
parent
0d3a7b9393
commit
df429b617e
@ -1,89 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
-- TODO make compatible with lovr
|
|
||||||
if ISTHREAD then
|
|
||||||
error("You cannot require the lovrManager from within a thread!")
|
|
||||||
end
|
|
||||||
local ThreadFileData = [[
|
|
||||||
ISTHREAD = true
|
|
||||||
THREAD = require("multi.integration.lovrManager.threads") -- order is important!
|
|
||||||
sThread = THREAD
|
|
||||||
__IMPORTS = {...}
|
|
||||||
__FUNC__=table.remove(__IMPORTS,1)
|
|
||||||
__THREADID__=table.remove(__IMPORTS,1)
|
|
||||||
__THREADNAME__=table.remove(__IMPORTS,1)
|
|
||||||
stab = THREAD.createStaticTable(__THREADNAME__)
|
|
||||||
GLOBAL = THREAD.getGlobal()
|
|
||||||
multi, thread = require("multi").init()
|
|
||||||
stab["returns"] = {THREAD.loadDump(__FUNC__)(unpack(__IMPORTS))}
|
|
||||||
]]
|
|
||||||
local multi, thread = require("multi.compat.lovr2d"):init()
|
|
||||||
local THREAD = {}
|
|
||||||
__THREADID__ = 0
|
|
||||||
__THREADNAME__ = "MainThread"
|
|
||||||
multi.integration={}
|
|
||||||
multi.integration.lovr2d={}
|
|
||||||
local THREAD = require("multi.integration.lovrManager.threads")
|
|
||||||
local GLOBAL = THREAD.getGlobal()
|
|
||||||
local THREAD_ID = 1
|
|
||||||
local OBJECT_ID = 0
|
|
||||||
local stf = 0
|
|
||||||
function THREAD:newFunction(func,holup)
|
|
||||||
stf = stf + 1
|
|
||||||
return function(...)
|
|
||||||
local t = multi:newSystemThread("STF"..stf,func,...)
|
|
||||||
return thread:newFunction(function()
|
|
||||||
return thread.hold(function()
|
|
||||||
if t.stab["returns"] then
|
|
||||||
local dat = t.stab.returns
|
|
||||||
t.stab.returns = nil
|
|
||||||
return unpack(dat)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end,holup)()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function multi:newSystemThread(name,func,...)
|
|
||||||
local c = {}
|
|
||||||
c.name = name
|
|
||||||
c.ID=THREAD_ID
|
|
||||||
c.thread=lovr.thread.newThread(ThreadFileData)
|
|
||||||
c.thread:start(THREAD.dump(func),c.ID,c.name,...)
|
|
||||||
c.stab = THREAD.createStaticTable(name)
|
|
||||||
GLOBAL["__THREAD_"..c.ID] = {ID=c.ID,Name=c.name,Thread=c.thread}
|
|
||||||
GLOBAL["__THREAD_COUNT"] = THREAD_ID
|
|
||||||
THREAD_ID=THREAD_ID+1
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
THREAD.newSystemThread = multi.newSystemThread
|
|
||||||
function lovr.threaderror(thread, errorstr)
|
|
||||||
print("Thread error!\n"..errorstr)
|
|
||||||
end
|
|
||||||
multi.integration.GLOBAL = GLOBAL
|
|
||||||
multi.integration.THREAD = THREAD
|
|
||||||
require("multi.integration.lovrManager.extensions")
|
|
||||||
print("Integrated lovr Threading!")
|
|
||||||
return {init=function()
|
|
||||||
return GLOBAL,THREAD
|
|
||||||
end}
|
|
||||||
@ -1,222 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
-- TODO make compatible with lovr
|
|
||||||
require("lovr.timer")
|
|
||||||
require("lovr.system")
|
|
||||||
require("lovr.data")
|
|
||||||
local socket = require("socket")
|
|
||||||
local multi, thread = require("multi").init()
|
|
||||||
local threads = {}
|
|
||||||
function threads.loadDump(d)
|
|
||||||
return loadstring(d:getString())
|
|
||||||
end
|
|
||||||
function threads.dump(func)
|
|
||||||
return lovr.data.newByteData(string.dump(func))
|
|
||||||
end
|
|
||||||
local fRef = {"func",nil}
|
|
||||||
local function manage(channel, value)
|
|
||||||
channel:clear()
|
|
||||||
if type(value) == "function" then
|
|
||||||
fRef[2] = THREAD.dump(value)
|
|
||||||
channel:push(fRef)
|
|
||||||
return
|
|
||||||
else
|
|
||||||
channel:push(value)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local function RandomVariable(length)
|
|
||||||
local res = {}
|
|
||||||
math.randomseed(socket.gettime()*10000)
|
|
||||||
for i = 1, length do
|
|
||||||
res[#res+1] = string.char(math.random(97, 122))
|
|
||||||
end
|
|
||||||
return table.concat(res)
|
|
||||||
end
|
|
||||||
local GNAME = "__GLOBAL_"
|
|
||||||
local proxy = {}
|
|
||||||
function threads.set(name,val)
|
|
||||||
if not proxy[name] then proxy[name] = lovr.thread.getChannel(GNAME..name) end
|
|
||||||
proxy[name]:performAtomic(manage, val)
|
|
||||||
end
|
|
||||||
function threads.get(name)
|
|
||||||
if not proxy[name] then proxy[name] = lovr.thread.getChannel(GNAME..name) end
|
|
||||||
local dat = proxy[name]:peek()
|
|
||||||
if type(dat)=="table" and dat[1]=="func" then
|
|
||||||
return THREAD.loadDump(dat[2])
|
|
||||||
else
|
|
||||||
return dat
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function threads.waitFor(name)
|
|
||||||
if thread.isThread() then
|
|
||||||
return thread.hold(function()
|
|
||||||
return threads.get(name)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
while threads.get(name)==nil do
|
|
||||||
lovr.timer.sleep(.001)
|
|
||||||
end
|
|
||||||
local dat = threads.get(name)
|
|
||||||
if type(dat) == "table" and dat.init then
|
|
||||||
dat.init = threads.loadDump(dat.init)
|
|
||||||
end
|
|
||||||
return dat
|
|
||||||
end
|
|
||||||
function threads.package(name,val)
|
|
||||||
local init = val.init
|
|
||||||
val.init=threads.dump(val.init)
|
|
||||||
GLOBAL[name]=val
|
|
||||||
val.init=init
|
|
||||||
end
|
|
||||||
function threads.getCores()
|
|
||||||
return lovr.system.getProcessorCount()
|
|
||||||
end
|
|
||||||
function threads.kill()
|
|
||||||
error("Thread Killed!")
|
|
||||||
end
|
|
||||||
function threads.getThreads()
|
|
||||||
local t = {}
|
|
||||||
for i=1,GLOBAL["__THREAD_COUNT"] do
|
|
||||||
t[#t+1]=GLOBAL["__THREAD_"..i]
|
|
||||||
end
|
|
||||||
return t
|
|
||||||
end
|
|
||||||
function threads.getThread(n)
|
|
||||||
return GLOBAL["__THREAD_"..n]
|
|
||||||
end
|
|
||||||
function threads.getName()
|
|
||||||
return __THREADNAME__
|
|
||||||
end
|
|
||||||
function threads.getID()
|
|
||||||
return __THREADID__
|
|
||||||
end
|
|
||||||
function threads.sleep(n)
|
|
||||||
lovr.timer.sleep(n)
|
|
||||||
end
|
|
||||||
function threads.getGlobal()
|
|
||||||
return setmetatable({},
|
|
||||||
{
|
|
||||||
__index = function(t, k)
|
|
||||||
return THREAD.get(k)
|
|
||||||
end,
|
|
||||||
__newindex = function(t, k, v)
|
|
||||||
THREAD.set(k,v)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
)
|
|
||||||
end
|
|
||||||
function threads.createTable(n)
|
|
||||||
local _proxy = {}
|
|
||||||
local function set(name,val)
|
|
||||||
if not _proxy[name] then _proxy[name] = lovr.thread.getChannel(n..name) end
|
|
||||||
_proxy[name]:performAtomic(manage, val)
|
|
||||||
end
|
|
||||||
local function get(name)
|
|
||||||
if not _proxy[name] then _proxy[name] = lovr.thread.getChannel(n..name) end
|
|
||||||
local dat = _proxy[name]:peek()
|
|
||||||
if type(dat)=="table" and dat[1]=="func" then
|
|
||||||
return THREAD.loadDump(dat[2])
|
|
||||||
else
|
|
||||||
return dat
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return setmetatable({},
|
|
||||||
{
|
|
||||||
__index = function(t, k)
|
|
||||||
return get(k)
|
|
||||||
end,
|
|
||||||
__newindex = function(t, k, v)
|
|
||||||
set(k,v)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
)
|
|
||||||
end
|
|
||||||
function threads.getConsole()
|
|
||||||
local c = {}
|
|
||||||
c.queue = lovr.thread.getChannel("__CONSOLE__")
|
|
||||||
function c.print(...)
|
|
||||||
c.queue:push{...}
|
|
||||||
end
|
|
||||||
function c.error(err)
|
|
||||||
c.queue:push{"ERROR in <"..__THREADNAME__..">: "..err,__THREADID__}
|
|
||||||
error(err)
|
|
||||||
end
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
if not ISTHREAD then
|
|
||||||
local clock = os.clock
|
|
||||||
local lastproc = clock()
|
|
||||||
local queue = lovr.thread.getChannel("__CONSOLE__")
|
|
||||||
thread:newThread("consoleManager",function()
|
|
||||||
while true do
|
|
||||||
thread.yield()
|
|
||||||
dat = queue:pop()
|
|
||||||
if dat then
|
|
||||||
lastproc = clock()
|
|
||||||
print(unpack(dat))
|
|
||||||
end
|
|
||||||
if clock()-lastproc>2 then
|
|
||||||
thread.sleep(.1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
function threads.createStaticTable(n)
|
|
||||||
local __proxy = {}
|
|
||||||
local function set(name,val)
|
|
||||||
if __proxy[name] then return end
|
|
||||||
local chan = lovr.thread.getChannel(n..name)
|
|
||||||
if chan:getCount()>0 then return end
|
|
||||||
chan:performAtomic(manage, val)
|
|
||||||
__proxy[name] = val
|
|
||||||
end
|
|
||||||
local function get(name)
|
|
||||||
if __proxy[name] then return __proxy[name] end
|
|
||||||
local dat = lovr.thread.getChannel(n..name):peek()
|
|
||||||
if type(dat)=="table" and dat[1]=="func" then
|
|
||||||
__proxy[name] = THREAD.loadDump(dat[2])
|
|
||||||
return __proxy[name]
|
|
||||||
else
|
|
||||||
__proxy[name] = dat
|
|
||||||
return __proxy[name]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return setmetatable({},
|
|
||||||
{
|
|
||||||
__index = function(t, k)
|
|
||||||
return get(k)
|
|
||||||
end,
|
|
||||||
__newindex = function(t, k, v)
|
|
||||||
set(k,v)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
)
|
|
||||||
end
|
|
||||||
function threads.hold(n)
|
|
||||||
local dat
|
|
||||||
while not(dat) do
|
|
||||||
dat = n()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return threads
|
|
||||||
@ -1,138 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
|
|
||||||
-- This module probably will not be maintained any longer!
|
|
||||||
package.path = "?/init.lua;?.lua;" .. package.path
|
|
||||||
local function _INIT(luvitThread, timer)
|
|
||||||
-- lots of this stuff should be able to stay the same
|
|
||||||
function os.getOS()
|
|
||||||
if package.config:sub(1, 1) == "\\" then
|
|
||||||
return "windows"
|
|
||||||
else
|
|
||||||
return "unix"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- Step 1 get setup threads on luvit... Sigh how do i even...
|
|
||||||
local multi, thread = require("multi").init()
|
|
||||||
isMainThread = true
|
|
||||||
function multi:canSystemThread()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
function multi:getPlatform()
|
|
||||||
return "luvit"
|
|
||||||
end
|
|
||||||
local multi = multi
|
|
||||||
-- Step 2 set up the Global table... is this possible?
|
|
||||||
local GLOBAL = {}
|
|
||||||
setmetatable(
|
|
||||||
GLOBAL,
|
|
||||||
{
|
|
||||||
__index = function(t, k)
|
|
||||||
--print("No Global table when using luvit integration!")
|
|
||||||
return nil
|
|
||||||
end,
|
|
||||||
__newindex = function(t, k, v)
|
|
||||||
--print("No Global table when using luvit integration!")
|
|
||||||
end
|
|
||||||
}
|
|
||||||
)
|
|
||||||
local THREAD = {}
|
|
||||||
function THREAD.set(name, val)
|
|
||||||
--print("No Global table when using luvit integration!")
|
|
||||||
end
|
|
||||||
function THREAD.get(name)
|
|
||||||
--print("No Global table when using luvit integration!")
|
|
||||||
end
|
|
||||||
local function randomString(n)
|
|
||||||
local str = ""
|
|
||||||
local strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
|
|
||||||
for i = 1, n do
|
|
||||||
str = str .. "" .. strings[math.random(1, #strings)]
|
|
||||||
end
|
|
||||||
return str
|
|
||||||
end
|
|
||||||
function THREAD.waitFor(name)
|
|
||||||
--print("No Global table when using luvit integration!")
|
|
||||||
end
|
|
||||||
function THREAD.testFor(name, val, sym)
|
|
||||||
--print("No Global table when using luvit integration!")
|
|
||||||
end
|
|
||||||
function THREAD.getCores()
|
|
||||||
return THREAD.__CORES
|
|
||||||
end
|
|
||||||
if os.getOS() == "windows" then
|
|
||||||
THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS"))
|
|
||||||
else
|
|
||||||
THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n"))
|
|
||||||
end
|
|
||||||
function THREAD.kill() -- trigger the thread destruction
|
|
||||||
error("Thread was Killed!")
|
|
||||||
end
|
|
||||||
-- hmmm if im cleaver I can get this to work... but since data passing isn't going to be a thing its probably not important
|
|
||||||
function THREAD.sleep(n)
|
|
||||||
--print("No Global table when using luvit integration!")
|
|
||||||
end
|
|
||||||
function THREAD.hold(n)
|
|
||||||
--print("No Global table when using luvit integration!")
|
|
||||||
end
|
|
||||||
-- Step 5 Basic Threads!
|
|
||||||
local function entry(path, name, func, ...)
|
|
||||||
local timer = require "timer"
|
|
||||||
local luvitThread = require "thread"
|
|
||||||
package.path = path
|
|
||||||
loadstring(func)(...)
|
|
||||||
end
|
|
||||||
function multi:newSystemThread(name, func, ...)
|
|
||||||
local c = {}
|
|
||||||
local __self = c
|
|
||||||
c.name = name
|
|
||||||
c.Type = "sthread"
|
|
||||||
c.thread = {}
|
|
||||||
c.func = string.dump(func)
|
|
||||||
function c:kill()
|
|
||||||
-- print("No Global table when using luvit integration!")
|
|
||||||
end
|
|
||||||
luvitThread.start(entry, package.path, name, c.func, ...)
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
THREAD.newSystemThread = multi.newSystemThread
|
|
||||||
multi.print("Integrated Luvit!")
|
|
||||||
multi.integration = {} -- for module creators
|
|
||||||
multi.integration.GLOBAL = GLOBAL
|
|
||||||
multi.integration.THREAD = THREAD
|
|
||||||
require("multi.integration.shared")
|
|
||||||
-- Start the main mainloop... This allows you to process your multi objects, but the engine on the main thread will be limited to .001 or 1 millisecond sigh...
|
|
||||||
local interval =
|
|
||||||
timer.setInterval(
|
|
||||||
1,
|
|
||||||
function()
|
|
||||||
multi:uManager()
|
|
||||||
end
|
|
||||||
)
|
|
||||||
return multi
|
|
||||||
end
|
|
||||||
return {init = function(threadHandle, timerHandle)
|
|
||||||
local multi = _INIT(threadHandle, timerHandle)
|
|
||||||
return GLOBAL, THREAD
|
|
||||||
end}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
_G["__CHANNEL__"] = {}
|
|
||||||
local channel = {}
|
|
||||||
channel.__index = channel
|
|
||||||
|
|
||||||
-- Creates/Gets a channel of name
|
|
||||||
function channel:newChannel(name)
|
|
||||||
local chan = _G["__CHANNEL__"]
|
|
||||||
if chan then
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,46 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
local multi, thread = require("multi"):init()
|
|
||||||
local cmd = require("multi.integration.networkManager.cmds")
|
|
||||||
local node = require("multi.integration.networkManager.node")
|
|
||||||
local net = require("net")
|
|
||||||
local bin = require("bin")
|
|
||||||
local child = {}
|
|
||||||
child.__index = child
|
|
||||||
function multi:newChildNode(cd)
|
|
||||||
local c = {}
|
|
||||||
setmetatable(c,child)
|
|
||||||
local name
|
|
||||||
if cd then
|
|
||||||
if cd.name then
|
|
||||||
name = cd.name
|
|
||||||
end
|
|
||||||
c.node = node:new(cd.nodePort or cmd.defaultPort,nil,name)
|
|
||||||
if cd.managerHost then
|
|
||||||
cd.managerPort = cd.managerPort or cmd.defaultManagerPort
|
|
||||||
c.node:registerWithManager(cd.managerHost,cd.managerPort)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
return function(self,data)
|
|
||||||
local cmd,data = data:match("!(.-)!(.*)")
|
|
||||||
--print(">",cmd,data)
|
|
||||||
if cmd == "PONG" then
|
|
||||||
self:send("!PONG!")
|
|
||||||
elseif cmd == "CHANNEL" then
|
|
||||||
--
|
|
||||||
elseif cmd == "RETURNS" then
|
|
||||||
local rets = bin.new(data):getBlock("t")
|
|
||||||
self.node.master.OnDataReturned:Fire(rets)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
local cmds = {
|
|
||||||
defaultManagerPort = 0XDE2,
|
|
||||||
defaultWait = 0X002,
|
|
||||||
defaultPort = 0X000, -- We will let the OS assign us one
|
|
||||||
standardSkip = 0X018,
|
|
||||||
ERROR = 0X000,
|
|
||||||
PING = 0X001,
|
|
||||||
PONG = 0X002,
|
|
||||||
QUEUE = 0X003,
|
|
||||||
TASK = 0X004,
|
|
||||||
INITNODE = 0X005,
|
|
||||||
INITMASTER = 0X006,
|
|
||||||
GLOBAL = 0X007,
|
|
||||||
LOAD = 0X008,
|
|
||||||
CALL = 0X009,
|
|
||||||
REG = 0X00A,
|
|
||||||
CONSOLE = 0X00B,
|
|
||||||
}
|
|
||||||
return cmds
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
@ -1,163 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
local multi, thread = require("multi"):init()
|
|
||||||
local cmd = require("multi.integration.networkManager.cmds")
|
|
||||||
local node = require("multi.integration.networkManager.node")
|
|
||||||
local net = require("net")
|
|
||||||
local bin = require("bin")
|
|
||||||
local master = {}
|
|
||||||
master.__index = master
|
|
||||||
function master:addNode(ip,port)
|
|
||||||
return node:new(ip,port)
|
|
||||||
end
|
|
||||||
function master:getNodesFromBroadcast()
|
|
||||||
net:newCastedClients("NODE_.+")
|
|
||||||
net.OnCastedClientInfo(function(client, n, ip, port)
|
|
||||||
self.nodes[n] = node:new(client)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
function master:getNodesFromManager(ip,port)
|
|
||||||
local mn = self.nodes
|
|
||||||
if not self.manager then
|
|
||||||
self.manager = net:newTCPClient(ip,port)
|
|
||||||
if not self.manager then
|
|
||||||
error("Unable to connect to the node Manager! Is it running? Perhaps the hostname or port is incorrect!")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.manager.OnDataRecieved(function(self,data,client)
|
|
||||||
local cmd = data:match("!(.+)!")
|
|
||||||
data = data:gsub("!"..cmd.."!","")
|
|
||||||
if cmd == "NODE" then
|
|
||||||
local n,h,p = data:match("(.-)|(.-)|(.+)")
|
|
||||||
mn[n] = node:new(h,tonumber(p))
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
self.manager:send("!NODES!")
|
|
||||||
end
|
|
||||||
function master:setDefaultNode(nodeName)
|
|
||||||
if self:nodeExists(nodeName) then
|
|
||||||
self.defaultNode = nodeName
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function master:getRandomNode()
|
|
||||||
local t = {}
|
|
||||||
for i,v in pairs(self.nodes) do t[#t+1] = i end
|
|
||||||
return t[math.random(1,#t)]
|
|
||||||
end
|
|
||||||
local netID = 0
|
|
||||||
function master:newNetworkThread(nodeName,func,...)
|
|
||||||
local args = {...}
|
|
||||||
local dat = bin.new()
|
|
||||||
local ret
|
|
||||||
local nID = netID
|
|
||||||
local conn = multi:newConnection()
|
|
||||||
thread:newthread(function()
|
|
||||||
dat:addBlock{
|
|
||||||
args = args,
|
|
||||||
func = func,
|
|
||||||
id = netID
|
|
||||||
}
|
|
||||||
netID = netID + 1
|
|
||||||
if type(nodeName) == "function" then
|
|
||||||
func = nodeName
|
|
||||||
nodeName = self.defaultNode or self:getRandomNode()
|
|
||||||
if not func then
|
|
||||||
error("You must provide a function!")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self:sendTo(nodeName,"!N_THREAD!"..dat.data)
|
|
||||||
self.OnDataReturned(function(rets)
|
|
||||||
if rets.ID == nID then
|
|
||||||
conn:Fire(unpack(rets.rets))
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
return conn
|
|
||||||
end
|
|
||||||
function master:newNetworkChannel(nodeName)
|
|
||||||
--
|
|
||||||
end
|
|
||||||
function master:sendTo(nodeName,data)
|
|
||||||
self:queue("send",nodeName,data)
|
|
||||||
end
|
|
||||||
function master:demandNodeExistance(nodeName)
|
|
||||||
if self.nodes[nodeName] then
|
|
||||||
return multi.hold(self.nodes[nodeName]:ping().pong)
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function master:queue(c,...)
|
|
||||||
table.insert(self._queue,{c,{...}})
|
|
||||||
end
|
|
||||||
function multi:newMasterNode(cd)
|
|
||||||
local c = {}
|
|
||||||
setmetatable(c, master)
|
|
||||||
c.OnNodeDiscovered = multi:newConnection()
|
|
||||||
c.OnNodeRemoved = multi:newConnection()
|
|
||||||
c.OnDataRecieved = multi:newConnection()
|
|
||||||
c.OnDataReturned = multi:newConnection()
|
|
||||||
c.defaultNode = ""
|
|
||||||
c.nodes = {}
|
|
||||||
setmetatable(c.nodes,
|
|
||||||
{__newindex = function(t,k,v)
|
|
||||||
rawset(t,k,v)
|
|
||||||
v.master = c
|
|
||||||
c.OnNodeDiscovered:Fire(k,v)
|
|
||||||
end})
|
|
||||||
c._queue = {}
|
|
||||||
if cd then
|
|
||||||
if cd.nodeHost then
|
|
||||||
cd.nodePort = cd.nodePort or cmd.defaultPort
|
|
||||||
local n,no = c:addNode(cd.nodeHost,cd.nodePort)
|
|
||||||
if n then
|
|
||||||
c.nodes[n] = no
|
|
||||||
end
|
|
||||||
elseif cd.managerHost then
|
|
||||||
cd.managerPort = cd.managerPort or cmd.defaultManagerPort
|
|
||||||
c:getNodesFromManager(cd.managerHost,cd.managerPort)
|
|
||||||
else
|
|
||||||
c:getNodesFromBroadcast()
|
|
||||||
end
|
|
||||||
else
|
|
||||||
c:getNodesFromBroadcast()
|
|
||||||
end
|
|
||||||
thread:newthread("CMDQueueProcessor",function()
|
|
||||||
while true do
|
|
||||||
thread.skip(128)
|
|
||||||
local data = table.remove(c._queue,1)
|
|
||||||
if data then
|
|
||||||
local cmd = data[1]
|
|
||||||
if cmd == "send" then
|
|
||||||
local nodeName = data[2][1]
|
|
||||||
local dat = data[2][2]
|
|
||||||
c.nodes[nodeName]:send(dat)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end):OnError(function(...)
|
|
||||||
print(...)
|
|
||||||
end)
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
@ -1,127 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
local net = require("net")
|
|
||||||
local cmd = require("multi.integration.networkManager.cmds")
|
|
||||||
local multi,thread = require("multi"):init()
|
|
||||||
local node = {}
|
|
||||||
node.__index = node
|
|
||||||
local rand = {}
|
|
||||||
for i = 65,90 do
|
|
||||||
rand[#rand+1] = string.char(i)
|
|
||||||
end
|
|
||||||
local function randName(n)
|
|
||||||
local str = {}
|
|
||||||
for i=1,(n or 10) do
|
|
||||||
str[#str+1] = rand[math.random(1,#rand)]
|
|
||||||
end
|
|
||||||
return table.concat(str)
|
|
||||||
end
|
|
||||||
local getNames = thread:newFunction(function(names)
|
|
||||||
local listen = socket.udp() -- make a new socket
|
|
||||||
listen:setsockname(net.getLocalIP(), 11111)
|
|
||||||
listen:settimeout(0)
|
|
||||||
local data, ip, port = listen:receivefrom()
|
|
||||||
thread.holdWithin(1,function()
|
|
||||||
if data then
|
|
||||||
local n, tp, ip, port = data:match("(%S-)|(%S-)|(%S-):(%d+)")
|
|
||||||
if n then
|
|
||||||
names[n]=true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
return multi.NIL
|
|
||||||
end)
|
|
||||||
local function setName(ref,name)
|
|
||||||
if name then
|
|
||||||
ref.name = "NODE_"..name
|
|
||||||
ref.connection:broadcast(name)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local names = {}
|
|
||||||
getNames(names).wait() -- Prevents duplicate names from spawning!
|
|
||||||
local name = randName()
|
|
||||||
while names["NODE_"..name] do
|
|
||||||
name = randName()
|
|
||||||
end
|
|
||||||
ref.name = "NODE_"..name
|
|
||||||
ref.connection:broadcast(ref.name)
|
|
||||||
end
|
|
||||||
node.ServerCode = require("multi.integration.networkManager.serverSide")
|
|
||||||
node.ClientCode = require("multi.integration.networkManager.clientSide")
|
|
||||||
function node.random()
|
|
||||||
return randName(12)
|
|
||||||
end
|
|
||||||
function node:registerWithManager(ip,port)
|
|
||||||
if self.type ~= "server" then return end
|
|
||||||
if not self.manager then
|
|
||||||
self.manager = net:newTCPClient(ip,port)
|
|
||||||
if not self.manager then
|
|
||||||
error("Unable to connect to the node Manager! Is it running? Perhaps the hostname or port is incorrect!")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
thread:newFunction(function()
|
|
||||||
thread.hold(function() return self.name end)
|
|
||||||
self.manager:send("!REG_NODE!"..self.name.."|"..net.getLocalIP().."|"..self.connection.port)
|
|
||||||
end)()
|
|
||||||
end
|
|
||||||
function node:new(host,port,name)
|
|
||||||
local c = {}
|
|
||||||
c.links = {}
|
|
||||||
setmetatable(c,node)
|
|
||||||
if type(host)=="number" or type(host)=="nil" then
|
|
||||||
c.connection = net:newTCPServer(host or cmd.defaultPort)
|
|
||||||
c.connection:enableBinaryMode()
|
|
||||||
c.type = "server"
|
|
||||||
c.connection.node = c
|
|
||||||
c.connection.OnDataRecieved(self.ServerCode)
|
|
||||||
setName(c)
|
|
||||||
elseif type(host)=="table" and host.Type == "tcp" then
|
|
||||||
c.connection = host
|
|
||||||
c.connection:enableBinaryMode()
|
|
||||||
c.type = "client"
|
|
||||||
c.connection.node = c
|
|
||||||
c.connection.OnDataRecieved(self.ClientCode)
|
|
||||||
c.name = "MASTER_NODE"
|
|
||||||
elseif type(host) == "string" and type(port)=="number" then
|
|
||||||
c.connection = net:newTCPClient(host, port)
|
|
||||||
c.connection:enableBinaryMode()
|
|
||||||
c.type = "client"
|
|
||||||
c.connection.node = c
|
|
||||||
c.connection.OnDataRecieved(self.ClientCode)
|
|
||||||
c.name = "MASTER_NODE"
|
|
||||||
else
|
|
||||||
error("Invalid arguments!")
|
|
||||||
end
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
function node:ping()
|
|
||||||
if self.type ~= "client" then return end
|
|
||||||
self:send("!PING!")
|
|
||||||
return {pong=self.connection.OnDataRecieved}
|
|
||||||
end
|
|
||||||
function node:send(data)
|
|
||||||
if self.type ~= "client" then return end
|
|
||||||
self.connection:send(data)
|
|
||||||
end
|
|
||||||
return node
|
|
||||||
@ -1,48 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
local multi, thread = require("multi"):init()
|
|
||||||
local cmd = require("multi.integration.networkManager.cmds")
|
|
||||||
local net = require("net")
|
|
||||||
local bin = require("bin")
|
|
||||||
local nodes = { -- Testing stuff
|
|
||||||
|
|
||||||
}
|
|
||||||
function multi:newNodeManager(port)
|
|
||||||
print("Running node manager on port: "..(port or cmd.defaultManagerPort))
|
|
||||||
local server = net:newTCPServer(port or cmd.defaultManagerPort)
|
|
||||||
server.OnDataRecieved(function(serv, data, client)
|
|
||||||
local cmd = data:match("!(.+)!")
|
|
||||||
data = data:gsub("!"..cmd.."!","")
|
|
||||||
if cmd == "NODES" then
|
|
||||||
for i,v in ipairs(nodes) do
|
|
||||||
-- Sample data
|
|
||||||
serv:send(client, "!NODE!".. v[1].."|"..v[2].."|"..v[3])
|
|
||||||
end
|
|
||||||
elseif cmd == "REG_NODE" then
|
|
||||||
local name, ip, port = data:match("(.-)|(.-)|(.+)")
|
|
||||||
table.insert(nodes,{name,ip,port})
|
|
||||||
print("Registering Node:",name, ip, port)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
local bin, bits = require("bin").init()
|
|
||||||
return function(self,data,client)
|
|
||||||
local cmd,data = data:match("!(.-)!(.*)")
|
|
||||||
--print("SERVER",cmd,data)
|
|
||||||
if cmd == "PING" then
|
|
||||||
self:send(client,"!PONG!")
|
|
||||||
elseif cmd == "N_THREAD" then
|
|
||||||
print(1)
|
|
||||||
local dat = bin.new(data)
|
|
||||||
print(2)
|
|
||||||
local t = dat:getBlock("t")
|
|
||||||
print(3)
|
|
||||||
local ret = bin.new()
|
|
||||||
print(4)
|
|
||||||
ret:addBlock{ID = t.id,rets = {t.func(unpack(t.args))}}
|
|
||||||
print(5)
|
|
||||||
print(client,"!RETURNS!"..ret:getData())
|
|
||||||
self:send(client,"!RETURNS!"..ret:getData())
|
|
||||||
print(6)
|
|
||||||
elseif cmd == "CHANNEL" then
|
|
||||||
local dat = bin.new(data):getBlock("t")
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
local bin = require("bin")
|
|
||||||
local utils = {}
|
|
||||||
-- Will contain data that handles sterilizing and managing data
|
|
||||||
return utils
|
|
||||||
@ -1,141 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
local multi, thread = require("multi"):init()
|
|
||||||
local GLOBAL, THREAD = multi.integration.GLOBAL,multi.integration.THREAD
|
|
||||||
|
|
||||||
local function stripUpValues(func)
|
|
||||||
local dmp = string.dump(func)
|
|
||||||
if setfenv then
|
|
||||||
return loadstring(dmp,"IsolatedThread_PesudoThreading")
|
|
||||||
else
|
|
||||||
return load(dmp,"IsolatedThread_PesudoThreading","bt")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function multi:newSystemThreadedQueue(name)
|
|
||||||
local c = {}
|
|
||||||
function c:push(v)
|
|
||||||
table.insert(self,v)
|
|
||||||
end
|
|
||||||
function c:pop()
|
|
||||||
return table.remove(self,1)
|
|
||||||
end
|
|
||||||
function c:peek()
|
|
||||||
return self[1]
|
|
||||||
end
|
|
||||||
function c:init()
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
GLOBAL[name or "_"] = c
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
function multi:newSystemThreadedTable(name)
|
|
||||||
local c = {}
|
|
||||||
function c:init()
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
GLOBAL[name or "_"] = c
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
local setfenv = setfenv
|
|
||||||
if not setfenv then
|
|
||||||
if not debug then
|
|
||||||
multi.print("Unable to implement setfenv in lua 5.2+ the debug module is not available!")
|
|
||||||
else
|
|
||||||
setfenv = function(f, env)
|
|
||||||
return load(string.dump(f), nil, nil, env)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function multi:newSystemThreadedJobQueue(n)
|
|
||||||
local c = {}
|
|
||||||
c.cores = n or THREAD.getCores()*2
|
|
||||||
c.OnJobCompleted = multi:newConnection()
|
|
||||||
local jobs = {}
|
|
||||||
local ID=1
|
|
||||||
local jid = 1
|
|
||||||
local env = {}
|
|
||||||
setmetatable(env,{
|
|
||||||
__index = _G
|
|
||||||
})
|
|
||||||
local funcs = {}
|
|
||||||
function c:doToAll(func)
|
|
||||||
setfenv(func,env)()
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
function c:registerFunction(name,func)
|
|
||||||
funcs[name] = setfenv(func,env)
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
function c:pushJob(name,...)
|
|
||||||
table.insert(jobs,{name,jid,{...}})
|
|
||||||
jid = jid + 1
|
|
||||||
return jid-1
|
|
||||||
end
|
|
||||||
function c:isEmpty()
|
|
||||||
print(#jobs)
|
|
||||||
return #jobs == 0
|
|
||||||
end
|
|
||||||
local nFunc = 0
|
|
||||||
function c:newFunction(name,func,holup) -- This registers with the queue
|
|
||||||
local func = stripUpValues(func)
|
|
||||||
if type(name)=="function" then
|
|
||||||
holup = func
|
|
||||||
func = name
|
|
||||||
name = "JQ_Function_"..nFunc
|
|
||||||
end
|
|
||||||
nFunc = nFunc + 1
|
|
||||||
c:registerFunction(name,func)
|
|
||||||
return thread:newFunction(function(...)
|
|
||||||
local id = c:pushJob(name,...)
|
|
||||||
local link
|
|
||||||
local rets
|
|
||||||
link = c.OnJobCompleted(function(jid,...)
|
|
||||||
if id==jid then
|
|
||||||
rets = {...}
|
|
||||||
link:Destroy()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
return thread.hold(function()
|
|
||||||
if rets then
|
|
||||||
return unpack(rets) or multi.NIL
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end,holup),name
|
|
||||||
end
|
|
||||||
for i=1,c.cores do
|
|
||||||
thread:newthread("PesudoThreadedJobQueue_"..i,function()
|
|
||||||
while true do
|
|
||||||
thread.yield()
|
|
||||||
if #jobs>0 then
|
|
||||||
local j = table.remove(jobs,1)
|
|
||||||
c.OnJobCompleted:Fire(j[2],funcs[j[1]](unpack(j[3])))
|
|
||||||
else
|
|
||||||
thread.sleep(.05)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
@ -1,101 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2020 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
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()
|
|
||||||
|
|
||||||
if multi.integration then
|
|
||||||
return {
|
|
||||||
init = function()
|
|
||||||
return multi.integration.GLOBAL, multi.integration.THREAD
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
local GLOBAL, THREAD = require("multi.integration.pesudoManager.threads").init(thread)
|
|
||||||
|
|
||||||
function multi:canSystemThread() -- We are emulating system threading
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function multi:getPlatform()
|
|
||||||
return "pesudo"
|
|
||||||
end
|
|
||||||
|
|
||||||
local function split(str)
|
|
||||||
local tab = {}
|
|
||||||
for word in string.gmatch(str, '([^,]+)') do
|
|
||||||
table.insert(tab,word)
|
|
||||||
end
|
|
||||||
return tab
|
|
||||||
end
|
|
||||||
|
|
||||||
local tab = [[_VERSION,io,os,require,load,debug,assert,collectgarbage,error,getfenv,getmetatable,ipairs,loadstring,module,next,pairs,pcall,print,rawequal,rawget,rawset,select,setfenv,setmetatable,tonumber,tostring,type,unpack,xpcall,math,coroutine,string,table]]
|
|
||||||
tab = split(tab)
|
|
||||||
|
|
||||||
local id = 0
|
|
||||||
function multi:newSystemThread(name,func,...)
|
|
||||||
GLOBAL["$THREAD_NAME"] = name
|
|
||||||
GLOBAL["$__THREADNAME__"] = name
|
|
||||||
GLOBAL["$THREAD_ID"] = id
|
|
||||||
GLOBAL["$thread"] = thread
|
|
||||||
local env = {
|
|
||||||
GLOBAL = GLOBAL,
|
|
||||||
THREAD = THREAD,
|
|
||||||
THREAD_NAME = name,
|
|
||||||
__THREADNAME__ = name,
|
|
||||||
THREAD_ID = id,
|
|
||||||
thread = thread
|
|
||||||
}
|
|
||||||
|
|
||||||
for i = 1,#tab do
|
|
||||||
env[tab[i]] = _G[tab[i]]
|
|
||||||
end
|
|
||||||
|
|
||||||
local th = thread:newISOThread(name,func,env,...)
|
|
||||||
|
|
||||||
id = id + 1
|
|
||||||
|
|
||||||
return th
|
|
||||||
end
|
|
||||||
|
|
||||||
THREAD.newSystemThread = multi.newSystemThread
|
|
||||||
-- System threads as implemented here cannot share memory, but use a message passing system.
|
|
||||||
-- An isolated thread allows us to mimic that behavior so if access data from the "main" thread happens things will not work. This behavior is in line with how the system threading works
|
|
||||||
|
|
||||||
function THREAD:newFunction(func,holdme)
|
|
||||||
return thread:newFunctionBase(function(...)
|
|
||||||
return multi:newSystemThread("TempSystemThread",func,...)
|
|
||||||
end,holdme)()
|
|
||||||
end
|
|
||||||
|
|
||||||
multi.print("Integrated Pesudo Threading!")
|
|
||||||
multi.integration = {} -- for module creators
|
|
||||||
multi.integration.GLOBAL = GLOBAL
|
|
||||||
multi.integration.THREAD = THREAD
|
|
||||||
require("multi.integration.pesudoManager.extensions")
|
|
||||||
return {
|
|
||||||
init = function()
|
|
||||||
return GLOBAL, THREAD
|
|
||||||
end
|
|
||||||
}
|
|
||||||
@ -1,110 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
|
|
||||||
local function getOS()
|
|
||||||
if package.config:sub(1, 1) == "\\" then
|
|
||||||
return "windows"
|
|
||||||
else
|
|
||||||
return "unix"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function INIT(thread)
|
|
||||||
local THREAD = {}
|
|
||||||
local GLOBAL = {}
|
|
||||||
THREAD.Priority_Core = 3
|
|
||||||
THREAD.Priority_High = 2
|
|
||||||
THREAD.Priority_Above_Normal = 1
|
|
||||||
THREAD.Priority_Normal = 0
|
|
||||||
THREAD.Priority_Below_Normal = -1
|
|
||||||
THREAD.Priority_Low = -2
|
|
||||||
THREAD.Priority_Idle = -3
|
|
||||||
|
|
||||||
function THREAD.set(name, val)
|
|
||||||
GLOBAL[name] = val
|
|
||||||
end
|
|
||||||
|
|
||||||
function THREAD.get(name)
|
|
||||||
return GLOBAL[name]
|
|
||||||
end
|
|
||||||
|
|
||||||
function THREAD.waitFor(name)
|
|
||||||
return thread.hold(function() return GLOBAL[name] end)
|
|
||||||
end
|
|
||||||
|
|
||||||
if getOS() == "windows" then
|
|
||||||
THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS"))
|
|
||||||
else
|
|
||||||
THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function THREAD.getCores()
|
|
||||||
return THREAD.__CORES
|
|
||||||
end
|
|
||||||
|
|
||||||
function THREAD.getConsole()
|
|
||||||
local c = {}
|
|
||||||
function c.print(...)
|
|
||||||
print(...)
|
|
||||||
end
|
|
||||||
function c.error(err)
|
|
||||||
error("ERROR in <"..GLOBAL["$__THREADNAME__"]..">: "..err)
|
|
||||||
end
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
|
|
||||||
function THREAD.getThreads()
|
|
||||||
return {}--GLOBAL.__THREADS__
|
|
||||||
end
|
|
||||||
|
|
||||||
THREAD.pushStatus = thread.pushStatus
|
|
||||||
|
|
||||||
if os.getOS() == "windows" then
|
|
||||||
THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS"))
|
|
||||||
else
|
|
||||||
THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function THREAD.kill()
|
|
||||||
error("Thread was killed!")
|
|
||||||
end
|
|
||||||
|
|
||||||
function THREAD.getName()
|
|
||||||
return GLOBAL["$THREAD_NAME"]
|
|
||||||
end
|
|
||||||
|
|
||||||
function THREAD.getID()
|
|
||||||
return GLOBAL["$THREAD_ID"]
|
|
||||||
end
|
|
||||||
|
|
||||||
THREAD.sleep = thread.sleep
|
|
||||||
|
|
||||||
THREAD.hold = thread.hold
|
|
||||||
|
|
||||||
return GLOBAL, THREAD
|
|
||||||
end
|
|
||||||
|
|
||||||
return {init = function(thread)
|
|
||||||
return INIT(thread)
|
|
||||||
end}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
-- We need to detect what enviroment we are running our code in.
|
|
||||||
return {
|
|
||||||
init = function()
|
|
||||||
if love then
|
|
||||||
return require("multi.integration.loveManager"):init()
|
|
||||||
else
|
|
||||||
if pcall(require,"lanes") then
|
|
||||||
return require("multi.integration.lanesManager"):init()
|
|
||||||
end
|
|
||||||
return require("multi.integration.pesudoManager"):init()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
|
||||||
@ -19,21 +19,21 @@ dependencies = {
|
|||||||
build = {
|
build = {
|
||||||
type = "builtin",
|
type = "builtin",
|
||||||
modules = {
|
modules = {
|
||||||
["multi"] = "multi/init.lua",
|
["multi"] = "init.lua",
|
||||||
["multi.integration.lanesManager"] = "multi/integration/lanesManager/init.lua",
|
["multi.integration.lanesManager"] = "integration/lanesManager/init.lua",
|
||||||
["multi.integration.lanesManager.extensions"] = "multi/integration/lanesManager/extensions.lua",
|
["multi.integration.lanesManager.extensions"] = "integration/lanesManager/extensions.lua",
|
||||||
["multi.integration.lanesManager.threads"] = "multi/integration/lanesManager/threads.lua",
|
["multi.integration.lanesManager.threads"] = "integration/lanesManager/threads.lua",
|
||||||
["multi.integration.loveManager"] = "multi/integration/loveManager/init.lua",
|
["multi.integration.loveManager"] = "integration/loveManager/init.lua",
|
||||||
["multi.integration.loveManager.extensions"] = "multi/integration/loveManager/extensions.lua",
|
["multi.integration.loveManager.extensions"] = "integration/loveManager/extensions.lua",
|
||||||
["multi.integration.loveManager.threads"] = "multi/integration/loveManager/threads.lua",
|
["multi.integration.loveManager.threads"] = "integration/loveManager/threads.lua",
|
||||||
--["multi.integration.lovrManager"] = "multi/integration/lovrManager/init.lua",
|
--["multi.integration.lovrManager"] = "integration/lovrManager/init.lua",
|
||||||
--["multi.integration.lovrManager.extensions"] = "multi/integration/lovrManager/extensions.lua",
|
--["multi.integration.lovrManager.extensions"] = "integration/lovrManager/extensions.lua",
|
||||||
--["multi.integration.lovrManager.threads"] = "multi/integration/lovrManager/threads.lua",
|
--["multi.integration.lovrManager.threads"] = "integration/lovrManager/threads.lua",
|
||||||
["multi.integration.pesudoManager"] = "multi/integration/pesudoManager/init.lua",
|
["multi.integration.pesudoManager"] = "integration/pesudoManager/init.lua",
|
||||||
["multi.integration.pesudoManager.extensions"] = "multi/integration/pesudoManager/extensions.lua",
|
["multi.integration.pesudoManager.extensions"] = "integration/pesudoManager/extensions.lua",
|
||||||
["multi.integration.pesudoManager.threads"] = "multi/integration/pesudoManager/threads.lua",
|
["multi.integration.pesudoManager.threads"] = "integration/pesudoManager/threads.lua",
|
||||||
["multi.integration.luvitManager"] = "multi/integration/luvitManager.lua",
|
["multi.integration.luvitManager"] = "integration/luvitManager.lua",
|
||||||
["multi.integration.threading"] = "multi/integration/threading.lua",
|
["multi.integration.threading"] = "integration/threading.lua",
|
||||||
--["multi.integration.networkManager"] = "multi/integration/networkManager.lua",
|
--["multi.integration.networkManager"] = "integration/networkManager.lua",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user