Script:add_thread
Creates a new top-level Thread in this script to run a specific function.
The function you pass in will receive the thread running it as parameter. Return values of the function (if any) are used in conjunction with Thread:join.
Usage
script:add_thread(function_to_thread)
Arguments
| Name | Type | Description |
|---|---|---|
function_to_thread | function(self: Thread): any | Function to be executed by the new thread. |
Returns
| Name | Type | Description |
|---|---|---|
thread | Thread | New thread created. |
Examples
local script = crystal.Script:new();
script:add_thread(function(self)
print("Hello from the thread");
end);
script:update(0); -- Prints "Hello from the thread"