Fixed some issues and worked on some stuff

This commit is contained in:
Ryan Ward 2020-02-21 15:16:58 -05:00
parent f5b9f093d6
commit 3a2bb0c737
3 changed files with 79 additions and 65 deletions

View File

@ -11,13 +11,13 @@ Full Update Showcase
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 multi,thread = require("multi"):init()
-- Testing job stuff
function pushJobs() function pushJobs()
multi.Jobs:newJob(function() multi.Jobs:newJob(function()
print("job called") print("job called")
end) -- No name job end) -- No name job
multi.Jobs:newJob(function() multi.Jobs:newJob(function()
print("job called2") print("job called2")
os.exit() -- This is the last thing callec. I link to end the loop when doing examples
end,"test") end,"test")
multi.Jobs:newJob(function() multi.Jobs:newJob(function()
print("job called3") print("job called3")
@ -31,21 +31,68 @@ jobsn[1]:removeJob() -- Select a job and remove it
multi.Jobs:removeJobs("test2") -- Remove all jobs names 'test2' 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.SetScheme(1) -- Jobs are internally a service, so setting scheme and priority
multi.Jobs.SetPriority(multi.Priority_Core) multi.Jobs.SetPriority(multi.Priority_Core)
-- Testing destroying and fixed connections
c = multi:newConnection()
c1 = c(function()
print("called 1")
end)
c2 = c(function()
print("called 2")
end)
c3 = c(function()
print("called 3")
end)
print(c1,c2.Type,c3)
c:Fire()
c2:Destroy()
print(c1,c2.Type,c3)
c:Fire()
c1:Destroy()
print(c1,c2.Type,c3)
c:Fire()
-- Destroying alarms and threads
local test = multi:newThread(function()
while true do
thread.sleep(1)
print("Hello!")
end
end)
test.OnDeath(function()
os.exit() -- This is the last thing callec. I link to end the loop when doing examples
end)
local alarm = multi:newAlarm(4):OnRing(function(a)
print(a.Type)
a:Destroy()
print(a.Type)
test:Destroy()
end)
multi:lightloop() multi:lightloop()
``` ```
Going Forward: Going Forward:
--- ---
- -
Added: Added:
--- ---
- Type: destroyed - 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. - 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.
Fixed:
---
- Issue with connections not returning a handler for managing a specified conn object.
Changed: Changed:
--- ---
- Destroying an object converts the object into a 'destroyed' type.
- connections now have type 'connector_link'
```lua
OnExample = multi:newConnection()
conn = OnExample(...)
print(conn.Type) -- connector_link
```
- Revamped the job system - Revamped the job system
- multi.Jobs:newJob() - multi.Jobs:newJob() — See Full Update Showcase
Removed: Removed:
--- ---

View File

@ -46,6 +46,7 @@ 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.Priority_Core = 1 multi.Priority_Core = 1
multi.Priority_Very_High = 4 multi.Priority_Very_High = 4
multi.Priority_High = 16 multi.Priority_High = 16
@ -443,9 +444,11 @@ function multi:newConnection(protect,func,kill)
local temp = { local temp = {
Link=self.func, Link=self.func,
func=func, func=func,
Type="connector_link",
ID=self.ID, ID=self.ID,
Parent=self, Parent=self,
Fire=function(self,...) }
function temp:Fire(...)
if self.Parent.lock then return end if self.Parent.lock then return end
if self.Parent.protect then if self.Parent.protect then
local t=pcall(self.func,...) local t=pcall(self.func,...)
@ -455,8 +458,8 @@ function multi:newConnection(protect,func,kill)
else else
return self.func(...) return self.func(...)
end end
end, end
Remove=function(self) function temp:Destroy()
for i=1,#self.Link do for i=1,#self.Link do
if self.Link[i][2]~=nil then if self.Link[i][2]~=nil then
if self.Link[i][2]==self.ID then if self.Link[i][2]==self.ID then
@ -464,13 +467,11 @@ function multi:newConnection(protect,func,kill)
self.remove=function() end self.remove=function() end
self.Link=nil self.Link=nil
self.ID=nil self.ID=nil
return true multi.setType(temp,multi.DestroyedObj)
end
end end
end end
end end
end,
}
temp.Destroy=temp.Remove
if name then if name then
self.connections[name]=temp self.connections[name]=temp
end end
@ -494,8 +495,9 @@ function multi:newConnection(protect,func,kill)
end end
return ret return ret
else else
conn_helper(self,tab[1],tab[2],tab[3]) return conn_helper(self,tab[1],tab[2],tab[3])
end end
end end
c.Connect=c.connect c.Connect=c.connect
c.GetConnection=c.getConnection c.GetConnection=c.getConnection

View File

@ -1,40 +1,5 @@
package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path
--local sterilizer = require("multi.integration.sterilization") --local sterilizer = require("multi.integration.sterilization")
local multi,thread = require("multi"):init() local multi,thread = require("multi"):init()
local test = multi:newThread(function()
while true do
thread.sleep(1)
print("Hello!")
end
end)
local alarm = multi:newAlarm(4):OnRing(function(a)
print(a.Type)
a:Destroy()
print(a.Type)
test:Destroy()
end)
multi:lightloop()
-- 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()
-- multi:newThread(function()
-- end) multi:lightloop()
-- 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()