Added a blackhole object

This commit is contained in:
Ryan Ward 2020-02-20 15:37:50 -05:00
parent f737516009
commit 87467afd17
3 changed files with 71 additions and 34 deletions

View File

@ -8,19 +8,43 @@ Table of contents
Full Update Showcase Full Update Showcase
--- ---
```lua ```lua
package.path="?.lua;?/init.lua;?.lua;"..package.path package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path
local multi, thread = require("multi"):init() local multi,thread = require("multi"):init()
GLOBAL,THREAD = require("multi.integration.lanesManager"):init()
function pushJobs()
multi.Jobs:newJob(function()
print("job called")
end) -- No name job
multi.Jobs:newJob(function()
print("job called2")
os.exit() -- This is the last thing callec. I link to end the loop when doing examples
end,"test")
multi.Jobs:newJob(function()
print("job called3")
end,"test2")
end
pushJobs()
pushJobs()
local jobs = multi.Jobs:getJobs() -- gets all jobs
local jobsn = multi.Jobs:getJobs("test") -- gets all jobs names 'test'
jobsn[1]:removeJob() -- Select a job and remove it
multi.Jobs:removeJobs("test2") -- Remove all jobs names 'test2'
multi.Jobs.SetScheme(1) -- Jobs are internally a service, so setting scheme and priority
multi.Jobs.SetPriority(multi.Priority_Core)
multi:lightloop()
``` ```
Going Forward: Going Forward:
--- ---
- -
Added: Added:
--- ---
- - Type: destroyed
- A special state of an object that causes that object to become immutable and callable. The object Type is always "destroyed" it cannot be changed. The object can be indexed to infinity without issue. Every part of the object can be called as if it were a function including the indexed parts. This is done incase you destroy an object and still use it somewhere. However, if you are expecting something from the object then you may still encounter an error, though the returned type is an instance of the destroyed object which can be indexed and called like normal. This object can be used in any way and no errors will come about with it.
Changed: Changed:
--- ---
- - Revamped the job system
- multi.Jobs:newJob()
Removed: Removed:
--- ---
- multi:newTrigger() — Connections do everything this thing could do and more. I plan on removing bloat features from the library anyway - multi:newTrigger() — Connections do everything this thing could do and more. I plan on removing bloat features from the library anyway

View File

@ -46,6 +46,18 @@ multi.clock = os.clock
multi.time = os.time multi.time = os.time
multi.LinkedPath = multi multi.LinkedPath = multi
multi.lastTime = clock() multi.lastTime = clock()
multi.DestroyedObj = {
Type = "destroyed",
}
local function uni()
return multi.DestroyedObj
end
setmetatable(multi.DestroyedObj, {
__index = function(t,k)
return setmetatable({},{__index = uni,__newindex = uni,__call = uni,__metatable = multi.DestroyedObj,__tostring = function() return "destroyed" end,__unm = uni,__add = uni,__sub = uni,__mul = uni,__div = uni,__mod = uni,__pow = uni,__concat = uni})
end,__newindex = uni,__call = uni,__metatable = multi.DestroyedObj,__tostring = function() return "destroyed" end,__unm = uni,__add = uni,__sub = uni,__mul = uni,__div = uni,__mod = uni,__pow = uni,__concat = uni
})
math.randomseed(os.time()) math.randomseed(os.time())
local mainloopActive = false local mainloopActive = false
local isRunning = false local isRunning = false
@ -804,13 +816,6 @@ function multi:newConnection(protect,func,kill)
end end
c.Connect=c.connect c.Connect=c.connect
c.GetConnection=c.getConnection c.GetConnection=c.getConnection
function c:tofile(path)
local m=bin.new()
m:addBlock(self.Type)
m:addBlock(self.func)
m:tofile(path)
return self
end
if not(ignoreconn) then if not(ignoreconn) then
multi:create(c) multi:create(c)
end end
@ -916,14 +921,6 @@ function multi:newTimer()
time=os.clock()-time time=os.clock()-time
return self return self
end end
function c:tofile(path)
local m=bin.new()
count=count+self:Get()
m:addBlock(self.Type)
m:addBlock(count)
m:tofile(path)
return self
end
self:create(c) self:create(c)
return c return c
end end
@ -1587,7 +1584,7 @@ function multi:newThread(name,func,...)
end end
c.creationTime = os.clock() c.creationTime = os.clock()
threadid = threadid + 1 threadid = threadid + 1
multi.create(multi,c) self:create(c)
return c return c
end end
function multi.initThreads(justThreads) function multi.initThreads(justThreads)

View File

@ -1,15 +1,31 @@
package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path
local multi,thread = require("multi"):init()
--local sterilizer = require("multi.integration.sterilization") --local sterilizer = require("multi.integration.sterilization")
multi.Jobs:newJob(function() local multi,thread = require("multi"):init()
print("job called") bin = multi.DestroyedObj
end) local file = bin.new()
multi.Jobs:newJob(function() local data = file:getData()
print("job called2") print(data)
end) -- function pushJobs()
multi.Jobs:newJob(function() -- multi.Jobs:newJob(function()
print("job called3") -- print("job called")
end) -- end) -- No name job
multi.Jobs.SetScheme(1) -- multi.Jobs:newJob(function()
multi.Jobs.SetPriority(multi.Priority_Core) -- print("job called2")
multi:lightloop() -- os.exit() -- This is the last thing callec. I link to end the loop when doing examples
-- end,"test")
-- multi.Jobs:newJob(function()
-- print("job called3")
-- end,"test2")
-- end
-- pushJobs()
-- pushJobs()
-- multi:newThread(function()
-- end)
-- local jobs = multi.Jobs:getJobs() -- gets all jobs
-- local jobsn = multi.Jobs:getJobs("test") -- gets all jobs names 'test'
-- jobsn[1]:removeJob() -- Select a job and remove it
-- multi.Jobs:removeJobs("test2") -- Remove all jobs names 'test2'
-- multi.Jobs.SetScheme(1) -- Jobs are internally a service, so setting scheme and priority
-- multi.Jobs.SetPriority(multi.Priority_Core)
-- multi:lightloop()