Writing tests, fixed some bugs with the library, testing luajit support
This commit is contained in:
parent
537dcf0db1
commit
997ea48b54
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
*.code-workspace
|
*.code-workspace
|
||||||
*.dat
|
*.dat
|
||||||
test.lua
|
test.lua
|
||||||
|
|||||||
12
changes.md
12
changes.md
@ -26,6 +26,7 @@ Added:
|
|||||||
|
|
||||||
Changed:
|
Changed:
|
||||||
---
|
---
|
||||||
|
- `multi.hold(n,opt)` now supports an option table like thread.hold does.
|
||||||
- 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
|
||||||
@ -73,15 +74,10 @@ Changed:
|
|||||||
|
|
||||||
- Fixed the getTaskDetails to handle the new format for threads
|
- Fixed the getTaskDetails to handle the new format for threads
|
||||||
|
|
||||||
### Developer Note:
|
|
||||||
|
|
||||||
Connections are one 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)
|
|
||||||
|
|
||||||
|
|
||||||
Removed:
|
Removed:
|
||||||
---
|
---
|
||||||
|
- `multi:newFunction(func)`
|
||||||
|
- `thread:newFunction(func)` Has many more features and replaces completely what this function did
|
||||||
|
|
||||||
- Calling Fire on a connection no longer returns anything! Now that internal features use connections, I noticed how slow connections are and have increased their speed quite a bit. From 50,000 Steps per seconds to almost 7 Million. All other features should work just fine. Only returning values has been removed
|
- Calling Fire on a connection no longer returns anything! Now that internal features use connections, I noticed how slow connections are and have increased their speed quite a bit. From 50,000 Steps per seconds to almost 7 Million. All other features should work just fine. Only returning values has been removed
|
||||||
|
|
||||||
@ -89,6 +85,8 @@ Fixed:
|
|||||||
---
|
---
|
||||||
- [Issue](https://github.com/rayaman/multi/issues/30) with Lanes crashing the lua state. Issue seems to be related to my filesystem
|
- [Issue](https://github.com/rayaman/multi/issues/30) with Lanes crashing the lua state. Issue seems to be related to my filesystem
|
||||||
- [Issue](https://github.com/rayaman/multi/issues/29) where System threaded functions not up to date with threaded functions
|
- [Issue](https://github.com/rayaman/multi/issues/29) where System threaded functions not up to date with threaded functions
|
||||||
|
- Issue where gettasksdetails would try to process a destroyed object causing it to crash
|
||||||
|
|
||||||
|
|
||||||
ToDo:
|
ToDo:
|
||||||
---
|
---
|
||||||
|
|||||||
2
jitpaths.lua
Normal file
2
jitpaths.lua
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
package.path = "./?/init.lua;C:/Luajit/lua/?.init.lua;C:/Luajit/lua/?.lua;"
|
||||||
|
package.cpath = "C:/Luajit/clib/?/core.dll;C:/Luajit/clib/?.dll;"
|
||||||
1
luapaths.lua
Normal file
1
luapaths.lua
Normal file
@ -0,0 +1 @@
|
|||||||
|
package.path = "./?/init.lua;?.lua;".. package.path
|
||||||
115
multi/init.lua
115
multi/init.lua
@ -114,7 +114,9 @@ function multi:getTasksDetails(t)
|
|||||||
name = " <"..name..">"
|
name = " <"..name..">"
|
||||||
end
|
end
|
||||||
count = count + 1
|
count = count + 1
|
||||||
table.insert(str,{v.Type:sub(1,1):upper()..v.Type:sub(2,-1)..name,multi.Round(os.clock()-v.creationTime,3),self.PriorityResolve[v.Priority],v.TID})
|
if not v.Type == "destroyed" then
|
||||||
|
table.insert(str,{v.Type:sub(1,1):upper()..v.Type:sub(2,-1)..name,multi.Round(os.clock()-v.creationTime,3),self.PriorityResolve[v.Priority],v.TID})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if count == 0 then
|
if count == 0 then
|
||||||
table.insert(str,{"Currently no processes running!","","",""})
|
table.insert(str,{"Currently no processes running!","","",""})
|
||||||
@ -202,9 +204,9 @@ local ignoreconn = true
|
|||||||
function multi:newConnection(protect,func,kill)
|
function multi:newConnection(protect,func,kill)
|
||||||
local c={}
|
local c={}
|
||||||
local call_funcs = {}
|
local call_funcs = {}
|
||||||
|
local lock = false
|
||||||
c.callback = func
|
c.callback = func
|
||||||
c.Parent=self
|
c.Parent=self
|
||||||
c.lock = false
|
|
||||||
setmetatable(c,{__call=function(self,...)
|
setmetatable(c,{__call=function(self,...)
|
||||||
local t = ...
|
local t = ...
|
||||||
if type(t)=="table" then
|
if type(t)=="table" then
|
||||||
@ -246,7 +248,7 @@ function multi:newConnection(protect,func,kill)
|
|||||||
c.Type='connector'
|
c.Type='connector'
|
||||||
c.func={}
|
c.func={}
|
||||||
c.ID=0
|
c.ID=0
|
||||||
c.protect=protect or false
|
local protect=protect or false
|
||||||
local connections={}
|
local connections={}
|
||||||
c.FC=0
|
c.FC=0
|
||||||
function c:holdUT(n)
|
function c:holdUT(n)
|
||||||
@ -274,16 +276,16 @@ function multi:newConnection(protect,func,kill)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function c:Lock()
|
function c:Lock()
|
||||||
c.lock = true
|
lock = true
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
function c:Unlock()
|
function c:Unlock()
|
||||||
c.lock = false
|
lock = false
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
if c.protect then
|
if protect then
|
||||||
function c:Fire(...)
|
function c:Fire(...)
|
||||||
if self.lock then return end
|
if lock then return end
|
||||||
for i=#call_funcs,1,-1 do
|
for i=#call_funcs,1,-1 do
|
||||||
if not call_funcs[i] then return end
|
if not call_funcs[i] then return end
|
||||||
pcall(call_funcs[i],...)
|
pcall(call_funcs[i],...)
|
||||||
@ -303,6 +305,9 @@ function multi:newConnection(protect,func,kill)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local fast = {}
|
local fast = {}
|
||||||
|
function c:getConnections()
|
||||||
|
return call_funcs
|
||||||
|
end
|
||||||
function c:fastMode()
|
function c:fastMode()
|
||||||
function self:Fire(...)
|
function self:Fire(...)
|
||||||
for i=1,#fast do
|
for i=1,#fast do
|
||||||
@ -356,8 +361,8 @@ function multi:newConnection(protect,func,kill)
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
function temp:Fire(...)
|
function temp:Fire(...)
|
||||||
if self.Parent.lock then return end
|
if lock then return end
|
||||||
if self.Parent.protect then
|
if protect then
|
||||||
local t=pcall(call_funcs,...)
|
local t=pcall(call_funcs,...)
|
||||||
if t then
|
if t then
|
||||||
return t
|
return t
|
||||||
@ -635,17 +640,17 @@ end
|
|||||||
function multi:newEvent(task)
|
function multi:newEvent(task)
|
||||||
local c=self:newBase()
|
local c=self:newBase()
|
||||||
c.Type='event'
|
c.Type='event'
|
||||||
c.Task=task or function() end
|
local task = task or function() end
|
||||||
function c:Act()
|
function c:Act()
|
||||||
local t = {self.Task(self)}
|
local t = task(self)
|
||||||
if t[1] then
|
if t then
|
||||||
self:Pause()
|
self:Pause()
|
||||||
self.returns = t
|
self.returns = t
|
||||||
c.OnEvent:Fire(self)
|
c.OnEvent:Fire(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function c:SetTask(func)
|
function c:SetTask(func)
|
||||||
self.Task=func
|
task=func
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
c.OnEvent = self:newConnection()
|
c.OnEvent = self:newConnection()
|
||||||
@ -656,20 +661,20 @@ end
|
|||||||
function multi:newUpdater(skip)
|
function multi:newUpdater(skip)
|
||||||
local c=self:newBase()
|
local c=self:newBase()
|
||||||
c.Type='updater'
|
c.Type='updater'
|
||||||
c.pos=1
|
local pos = 1
|
||||||
c.skip=skip or 1
|
local skip = skip or 1
|
||||||
function c:Act()
|
function c:Act()
|
||||||
if self.pos>=self.skip then
|
if pos >= skip then
|
||||||
self.pos=0
|
pos = 0
|
||||||
self.OnUpdate:Fire(self)
|
self.OnUpdate:Fire(self)
|
||||||
end
|
end
|
||||||
self.pos=self.pos+1
|
pos = pos+1
|
||||||
end
|
end
|
||||||
function c:SetSkip(n)
|
function c:SetSkip(n)
|
||||||
self.skip=n
|
skip=n
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
c.OnUpdate=self:newConnection()
|
c.OnUpdate = self:newConnection()
|
||||||
multi:create(c)
|
multi:create(c)
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
@ -727,32 +732,6 @@ function multi:newLoop(func)
|
|||||||
multi:create(c)
|
multi:create(c)
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
function multi:newFunction(func)
|
|
||||||
local c={}
|
|
||||||
c.func=func
|
|
||||||
c.Type = "mfunc"
|
|
||||||
mt={
|
|
||||||
__index=multi,
|
|
||||||
__call=function(self,...)
|
|
||||||
if self.Active then
|
|
||||||
return self:func(...)
|
|
||||||
end
|
|
||||||
return nil,true
|
|
||||||
end
|
|
||||||
}
|
|
||||||
c.Parent=self
|
|
||||||
function c:Pause()
|
|
||||||
self.Active=false
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
function c:Resume()
|
|
||||||
self.Active=true
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
setmetatable(c,mt)
|
|
||||||
multi:create(c)
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
|
|
||||||
function multi:newStep(start,reset,count,skip)
|
function multi:newStep(start,reset,count,skip)
|
||||||
local c=self:newBase()
|
local c=self:newBase()
|
||||||
@ -1100,10 +1079,10 @@ function thread.waitFor(name)
|
|||||||
thread.hold(function() return thread.get(name)~=nil end)
|
thread.hold(function() return thread.get(name)~=nil end)
|
||||||
return thread.get(name)
|
return thread.get(name)
|
||||||
end
|
end
|
||||||
function multi.hold(func,no)
|
function multi.hold(func,opt)
|
||||||
if thread.isThread() and not(no) then
|
if thread.isThread() then
|
||||||
if type(func) == "function" or type(func) == "table" then
|
if type(func) == "function" or type(func) == "table" then
|
||||||
return thread.hold(func)
|
return thread.hold(func,opt)
|
||||||
end
|
end
|
||||||
return thread.sleep(func)
|
return thread.sleep(func)
|
||||||
end
|
end
|
||||||
@ -1119,7 +1098,7 @@ function multi.hold(func,no)
|
|||||||
else
|
else
|
||||||
local rets
|
local rets
|
||||||
self:newThread("Hold_func",function()
|
self:newThread("Hold_func",function()
|
||||||
rets = {thread.hold(func)}
|
rets = {thread.hold(func,opt)}
|
||||||
death = true
|
death = true
|
||||||
end)
|
end)
|
||||||
while not death do
|
while not death do
|
||||||
@ -2166,31 +2145,19 @@ function multi:getLoad()
|
|||||||
if not multi.maxSpd then self:enableLoadDetection() end
|
if not multi.maxSpd then self:enableLoadDetection() end
|
||||||
if busy then return lastVal,last_step end
|
if busy then return lastVal,last_step end
|
||||||
local val = nil
|
local val = nil
|
||||||
if thread.isThread() then
|
local bench
|
||||||
local bench
|
self:benchMark(.01):OnBench(function(time,steps)
|
||||||
self:benchMark(.01):OnBench(function(time,steps)
|
bench = steps
|
||||||
bench = steps
|
bb = steps
|
||||||
bb = steps
|
end)
|
||||||
end)
|
_,timeout = multi.hold(function()
|
||||||
thread.hold(function()
|
return bench
|
||||||
return bench
|
end,{sleep=.011})
|
||||||
end)
|
if timeout then
|
||||||
bench = bench^1.5
|
bench = 150000
|
||||||
val = math.ceil((1-(bench/(multi.maxSpd/2.2)))*100)
|
|
||||||
else
|
|
||||||
busy = true
|
|
||||||
local bench
|
|
||||||
self:benchMark(.01):OnBench(function(time,steps)
|
|
||||||
bench = steps
|
|
||||||
bb = steps
|
|
||||||
end)
|
|
||||||
while not bench do
|
|
||||||
self:uManager()
|
|
||||||
end
|
|
||||||
bench = bench^1.5
|
|
||||||
val = math.ceil((1-(bench/(multi.maxSpd/2.2)))*100)
|
|
||||||
busy = false
|
|
||||||
end
|
end
|
||||||
|
bench = bench^1.5
|
||||||
|
val = math.ceil((1-(bench/(multi.maxSpd/2.2)))*100)
|
||||||
if val<0 then val = 0 end
|
if val<0 then val = 0 end
|
||||||
if val > 100 then val = 100 end
|
if val > 100 then val = 100 end
|
||||||
lastVal = val
|
lastVal = val
|
||||||
|
|||||||
14
test3.lua
14
test3.lua
@ -1,6 +1,8 @@
|
|||||||
package.path = "./?/init.lua;"..package.path
|
package.path = "./?.lua"
|
||||||
|
--require("jitpaths")
|
||||||
|
require("luapaths")
|
||||||
local multi,thread = require("multi"):init()
|
local multi,thread = require("multi"):init()
|
||||||
local GLOBAL,THREAD = require("multi.integration.lanesManager"):init()
|
--local GLOBAL,THREAD = require("multi.integration.lanesManager"):init()
|
||||||
|
|
||||||
-- func = THREAD:newFunction(function(a,b,c)
|
-- func = THREAD:newFunction(function(a,b,c)
|
||||||
-- print("Hello Thread!",a,b,c)
|
-- print("Hello Thread!",a,b,c)
|
||||||
@ -22,7 +24,13 @@ local GLOBAL,THREAD = require("multi.integration.lanesManager"):init()
|
|||||||
-- end)
|
-- end)
|
||||||
multi:benchMark(1):OnBench(function(sec,steps)
|
multi:benchMark(1):OnBench(function(sec,steps)
|
||||||
print("Steps:",steps)
|
print("Steps:",steps)
|
||||||
os.exit()
|
--os.exit()
|
||||||
|
end)
|
||||||
|
|
||||||
|
multi:newThread(function()
|
||||||
|
print(thread.hold(function()
|
||||||
|
return false
|
||||||
|
end,{sleep=1}))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
multi:mainloop()
|
multi:mainloop()
|
||||||
@ -1,3 +1,42 @@
|
|||||||
return function objectTests(multi,thread)
|
function objectTests(multi,thread)
|
||||||
print("Testing Alarms!")
|
local alarms,tsteps,steps,loops,tloops,updaters,events=false,0,0,0,0,0,false
|
||||||
end
|
print("Testing Basic Features. If this fails most other features will probably not work!")
|
||||||
|
multi:newAlarm(2):OnRing(function(a)
|
||||||
|
alarms = true
|
||||||
|
a:Destroy()
|
||||||
|
end)
|
||||||
|
multi:newTStep(1,10,1,.1):OnStep(function(t)
|
||||||
|
tsteps = tsteps + 1
|
||||||
|
end):OnEnd(function(step)
|
||||||
|
step:Destroy()
|
||||||
|
end)
|
||||||
|
multi:newStep(1,10):OnStep(function(s)
|
||||||
|
steps = steps + 1
|
||||||
|
end):OnEnd(function(step)
|
||||||
|
step:Destroy()
|
||||||
|
end)
|
||||||
|
local loop = multi:newLoop(function(l)
|
||||||
|
loops = loops + 1
|
||||||
|
end)
|
||||||
|
multi:newTLoop(function(t)
|
||||||
|
tloops = tloops + 1
|
||||||
|
end,.1)
|
||||||
|
local updater = multi:newUpdater(1):OnUpdate(function()
|
||||||
|
updaters = updaters + 1
|
||||||
|
end)
|
||||||
|
local event = multi:newEvent(function()
|
||||||
|
return alarms
|
||||||
|
end)
|
||||||
|
event.OnEvent(function(evnt)
|
||||||
|
events = true
|
||||||
|
print("Alarms: Ok")
|
||||||
|
print("Events: Ok")
|
||||||
|
if tsteps == 10 then print("TSteps: Ok") else print("TSteps: Bad!") end
|
||||||
|
if steps == 10 then print("Steps: Ok") else print("Steps: Bad!") end
|
||||||
|
if loops > 100 then print("Loops: Ok") else print("Loops: Bad!") end
|
||||||
|
if tloops > 10 then print("TLoops: Ok") else print("TLoops: Bad!") end
|
||||||
|
if updaters > 100 then print("Updaters: Ok") else print("Updaters: Bad!") end
|
||||||
|
end)
|
||||||
|
return event
|
||||||
|
end
|
||||||
|
return objectTests
|
||||||
@ -16,6 +16,20 @@ package.path="../?.lua;../?/init.lua;../?.lua;../?/?/init.lua;"..package.path
|
|||||||
This will be pushed directly to the master as tests start existing.
|
This will be pushed directly to the master as tests start existing.
|
||||||
]]
|
]]
|
||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
function runTest(path)
|
|
||||||
|
local good = false
|
||||||
end
|
runTest = thread:newFunction(function()
|
||||||
|
local objects = multi:newProcessor("Basic Object Tests")
|
||||||
|
objects.Start()
|
||||||
|
otest = require("tests/objectTests")(objects,thread)
|
||||||
|
thread.hold(otest.OnEvent)
|
||||||
|
print("Timers: Ok")
|
||||||
|
print("Connections: Ok")
|
||||||
|
print("Threads: Ok")
|
||||||
|
print(objects:getTasksDetails())
|
||||||
|
good = true
|
||||||
|
print("\nTests done")
|
||||||
|
os.exit()
|
||||||
|
end,true)
|
||||||
|
print(runTest())
|
||||||
|
multi:mainloop()
|
||||||
Loading…
x
Reference in New Issue
Block a user