Skip to content
Ryan Ward edited this page Jun 26, 2017 · 7 revisions

Objects

There are 4 main types of objects in the multi library

  1. Runners
  2. Actors
  3. Semi-Actors
  4. Non-Actors

Runners

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 runner

Note: 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 runner

So 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 runner

Now that we see how we can use Actors on a runner let's get into each Actor and how they work

Actors

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(number 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(function) - connects to the main event of an actor object. This will be noted on each object below
  • Reallocate(runner_other, index) -- More on this on the features page
  • FreeMainEvent() - frees all connections to the main event
  • ConnectFinal(function) - connects to the final event of an object. This will be noted on each object below
  • GetParentProcess() - returns the runner that is running the current object
  • Break() - breaks an object pausing it and triggering the OnBreak() Connection
  • OnBreak(function(self)) - a connection to the Break event on each actor
  • IsPaused() - returns true if an object is paused
  • IsActive() - returns true if an object is active
  • GetType() - returns the type of object that it is. The expected returns will be noted below with each object
  • Sleep(n)* - makes an object sleep for a while
  • SetTime(number n) - sets the time until an object should timeout
  • OnTimedOut(func) - triggers if an object times out. Note: an object will not time out unless you call SetTime(n) on it!
  • ResetTime(number n) - resets a timed out object
  • ResolveTimer(...) - triggers the OnTimerResloved event and passes along the arguments you pass
  • OnTimerResolved(function(self,...)) - is triggered by the ResolveTimer() function
  • Reset() - resets an object, in most cases this acts like Resume()
  • IsDone() - returns true if an object is done doing something. In most cases it works like IsActive()
  • NewCondition - creates a condition object features
  • NewRange() - creates a range object features
  • Condition() - tests a condition features

*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.

events

The event object has this structure

event:

  • function OnEvent(func) - A callback function that is triggered whenever said event happens
  • string Type

Semi-Actors

Non-Actors

Clone this wiki locally