crystal.Script

A script manages a hierarchical collection of threads.

Constructor

crystal.Script:new(startup_function)

The startup_function parameter is optional. If specified, the script will start with one top-level thread set to execute this function. This parameter is effectively a short hand for:

local script = crystal.Script:new();
script:add_thread(startup_function);

Methods

Starting threads

Name Description
add_thread Creates a new top-level Thread in this script.
run_thread Creates and immediately begins executing a new top-level thread in this script.

Updating threads

Name Description
delta_time Returns the delta time that was passed to the last update call.
signal Stops all threads that were scheduled to stop upon a specific signal. Runs all threads that were waiting for it.
time Returns the cumulative time passed to all update calls.
update Runs all threads that are not currently blocked by a call like join or wait_for.

Stopping threads

Name Description
stop_all_threads Stops all threads in this script.
stop_thread Stops a specific Thread.

Examples

local script = crystal.Script:new();

script:add_thread(function(self)
  while true then
    print("Oink");
    self:wait_frame();
  end
end);

script:add_thread(function(self)
  while true then
    print("Moo");
    self:wait_frame();
  end
end);

script:update(0); -- Prints "Oink" and "Moo" (in any order)
script:update(0); -- Prints "Oink" and "Moo" (in any order)
script:update(0); -- Prints "Oink" and "Moo" (in any order)

This site uses Just the Docs, a documentation theme for Jekyll.