-
Notifications
You must be signed in to change notification settings - Fork 1
Objects
There are 4 main types of objects in the multi library
As of right now there are only 2 Runners.
- Processors
- Queues (WIP) Note: I will document this when I get it working properly.
Processors inherit all of their methods from the multi namespace, while also adding a few methods of their own. A process acts exactly like the multi namespace as well. It does differ in some ways though. With the multi namespace you are not able to "pause" the main runner. Note: There are ways to do so, but it is important to know what you are doing first. Which you will when you are done reading this wiki 😄.
All processors are able to have Actors constructed and created on them. For example:
require("multi.all")
process=multi:newProcess() -- this can also load a file, to keep things really organized, I will show a simple example first then show the same thing being done within another file.
process:newTLoop(function(self)
print("Looping every second...")
end,1)
process:Start() -- starts the process
multi:mainloop() -- start the main runnerNote: I will not be giving the output to all examples on the wiki
As mentioned above you can load a process from file. This can only work if your lua environment allows for the usage of loadstring!
testfile.lua
process:newTLoop(function(self)
print("Looping every second...")
end,1)main.lua
require("multi.all")
pro=multi:newProcess("testfile.lua")
pro:Start() -- starts the process
multi:mainloop() -- start the main runnerSo as seen above Actors can be created on a process, however the objects we created were not on the main process. To create one on the main process we can do the same as above with just a slight change
require("multi.all")
multi:newTLoop(function(self)
print("Looping every second...")
end,1)
multi:mainloop() -- start the main runnerNow that we see how we can use Actors on a runner let's get into each Actor and how they work
Here is a list of every actor within the library
- events - runner:newEvent(function task(self))
- alarms - runner:newAlarm(number set)
- loops - runner:newLoop(function loop(dt,self)) Note: dt stands for the change in time from the objects creation
- tloops - runner:newTLoop(function loop(self), number set)
- steps - runner:newStep(number start,number endAt, [number count - defualts to 1 or -1], [number skip - defualts to 0])
- tsteps - runner:newTStep(number start,number endAt, [number count - defualts to 1 or -1], [number set - defualts to 1])
- updaters - runner:newUpdater([number skip -- defualts to 0])
- watchers - runnet:newWatcher(table namespace, string name)
All actors have a few methods in common. These methods are
- Pause() - Pauses the object
- Resume() - Resumes the object
- Destroy() - destroys the object
- Hold(n)* - holds an object where it is while it waits for something to happen. where 'n' is an event or time
- IsHeld() - returns true or false whether the object is in a hold or not
- WaitFor(obj)* - holds the object until
- OnMainConnect(func) - connects to the main event of an actor object. These will be noted on each object below
- Reallocate(runner_other, index) -- More on this on the
*Note: that only one object can be held at a time, and only on the main runner! If you need more flexibility use threads. The threading page will explain how this works. Its just like regular objects so you will understand that easily after grasping how each actor itself works.
The event object has this structure event: function OnEvent(func)