From 3a2bb0c737a355cc3c3a8277a75a51c94cf5ddf2 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Fri, 21 Feb 2020 15:16:58 -0500 Subject: [PATCH] Fixed some issues and worked on some stuff --- changes.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++--- multi/init.lua | 54 ++++++++++++++++++++++++++------------------------ test.lua | 37 +--------------------------------- 3 files changed, 79 insertions(+), 65 deletions(-) diff --git a/changes.md b/changes.md index ccd1709..f229003 100644 --- a/changes.md +++ b/changes.md @@ -11,13 +11,13 @@ Full Update Showcase package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path local multi,thread = require("multi"):init() +-- Testing job stuff 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") @@ -31,21 +31,68 @@ 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) +-- 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() ``` Going Forward: --- - + 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. - + +Fixed: +--- +- Issue with connections not returning a handler for managing a specified conn object. + 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 - - multi.Jobs:newJob() + - multi.Jobs:newJob() — See Full Update Showcase Removed: --- diff --git a/multi/init.lua b/multi/init.lua index 895d370..d8b40da 100644 --- a/multi/init.lua +++ b/multi/init.lua @@ -46,6 +46,7 @@ multi.clock = os.clock multi.time = os.time multi.LinkedPath = multi multi.lastTime = clock() + multi.Priority_Core = 1 multi.Priority_Very_High = 4 multi.Priority_High = 16 @@ -443,34 +444,34 @@ function multi:newConnection(protect,func,kill) local temp = { Link=self.func, func=func, + Type="connector_link", ID=self.ID, Parent=self, - Fire=function(self,...) - if self.Parent.lock then return end - if self.Parent.protect then - local t=pcall(self.func,...) - if t then - return t - end - else - return self.func(...) - end - end, - Remove=function(self) - for i=1,#self.Link do - if self.Link[i][2]~=nil then - if self.Link[i][2]==self.ID then - table.remove(self.Link,i) - self.remove=function() end - self.Link=nil - self.ID=nil - return true - end - end - end - end, } - temp.Destroy=temp.Remove + function temp:Fire(...) + if self.Parent.lock then return end + if self.Parent.protect then + local t=pcall(self.func,...) + if t then + return t + end + else + return self.func(...) + end + end + function temp:Destroy() + for i=1,#self.Link do + if self.Link[i][2]~=nil then + if self.Link[i][2]==self.ID then + table.remove(self.Link,i) + self.remove=function() end + self.Link=nil + self.ID=nil + multi.setType(temp,multi.DestroyedObj) + end + end + end + end if name then self.connections[name]=temp end @@ -494,8 +495,9 @@ function multi:newConnection(protect,func,kill) end return ret else - conn_helper(self,tab[1],tab[2],tab[3]) + return conn_helper(self,tab[1],tab[2],tab[3]) end + end c.Connect=c.connect c.GetConnection=c.getConnection diff --git a/test.lua b/test.lua index b3fab45..d5c06bb 100644 --- a/test.lua +++ b/test.lua @@ -1,40 +1,5 @@ package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path --local sterilizer = require("multi.integration.sterilization") 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) --- 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() \ No newline at end of file +multi:lightloop() \ No newline at end of file