Nanotube

(in ./Carbon/Nanotube.lua)

Funnels events and provides an event loop.


Methods

class public Nanotube:New()

Returns Nanotube

class public Nanotube:PlacementNew(Nanotube? out)

Returns Nanotube

object public Nanotube:Init()

Returns void

Creates or initializes a Nanotube object.


object public Nanotube:Fire(string name, ...)

Returns unumber

  • required name: The name of the event to fire.
  • optional ...: The arguments to pass to handlers for this event.

Fires an event by name and passes parameters to the handlers registered to it.

Returns the number of handlers that were triggered by this event.


object public Nanotube:On(string name, function method, [number priority])

Returns self

  • required name: The name of the event to hook to.
  • required method: The function to call when the event fires.
  • optional priority: The priority for this function call.

Hook up to an event with a method. An alias to Hook.


object public Nanotube:Once(string name, function method, [number priority])

Returns self

  • required name: The name of the event to hook to.
  • required method: The function to call when the event fires.
  • optional priority: The priority for this function call.

Hook up to an event with a method called only once.


object public Nanotube:After(unumber seconds, function method)

Returns self

  • required seconds: The seconds to wait before firing the method.
  • required method: The method to call.

Call the method once after a number of seconds have elapsed.


object public Nanotube:At(unumber time, function method)

Returns self

  • required time: The time to fire the method at.
  • required method: The method to call.

Call the method once at an exact time relative to the application timer.


object public Nanotube:Every(unumber period, function method)

Returns self

  • required period: How many seconds should elapse between callings of the method.
  • required method: The method to call.

Call the method every time a number of seconds have elapsed.


object public Nanotube:Hook(string name, function method, [number priority])

Returns self

  • required name: The name of the event to hook to.
  • required method: The function to call when the event fires.
  • optional priority: The priority for this function call.

Generic hook method used by Once and On.


object public Nanotube:Loop()

Returns self

Starts an event loop that automatically calls events.


object public Nanotube:Mirror(string name, Nanotube tube)

Returns self

  • required name: The event to mirror.
  • required tube: The Nanotube to mirror the event to.

Mirrors an event onto another Nanotube so that it will be executed there as well as here.

For mirroring all events, use MirrorAll.


object public Nanotube:MirrorAll(Nanotube tube)

Returns self

  • required tube: The Nanotube to mirror events to.

Mirrors all events onto another Nanotube so that they will be executed there as well as here.


object public Nanotube:Step(...)

Returns self

  • required ...: Arguments to pass to the "Step" event

Step the loop forward a single iteration and calls any outstanding events.


object public Nanotube:Stop()

Returns self

Break out of a loop started by Nanotube:Loop()


Properties

public Nanotube Nanotube.Global

A global Nanotube instance for use as a singleton.


public bool Nanotube.StepPeriod

How long this instance should sleep between steps, in seconds. Only used if UseSleep is enabled.


public bool Nanotube.UseSleep

Whether this instance should use Time.Sleep to prevent overutilization of the CPU.