The Script interface contains helper functions for manipulating scripts.
Related sample code
Other related reference items
Related help topics
callstack ( ) : stringReturns the current script call stack.
|
This function does not accept any parameters. |
string |
The current script call stack. |
configure_garbage_collection ( parameters )Configures the garbage collector.
|
parameters : | any(string, number)+ | One or more of the options listed under Garbage Collection Flags, each followed by the value to set for that option. The + notation indicates that there may be one or more instances of the specified type. The any(...) notation indicates that this item may be an instance of any of the types shown in the parentheses. |
This function does not return any values. |
For example:
stingray.Script.configure_garbage_collection(stingray.Script.MINIMUM_COLLECT_TIME_MS, 0.2, stingray.Script.MAXIMUM_GARBAGE, 0.4)
Other related reference items
deserialize ( string_rep ) : any(string, number, boolean, table, stingray.Vector3, stingray.Vector3Box, stingray.Matrix4x4, stingray.Matrix4x4Box, stingray.IdString32, stingray.IdString32Box, stingray.IdString64, stingray.IdString64Box)Deserializes an opaque string representation of a Lua object back to data.
|
string_rep : | string | The string to deserialize into an object. |
any(string, number, boolean, table, stingray.Vector3, stingray.Vector3Box, stingray.Matrix4x4, stingray.Matrix4x4Box, stingray.IdString32, stingray.IdString32Box, stingray.IdString64, stingray.IdString64Box) |
The deserialized Lua object. The any(...) notation indicates that this item may be an instance of any of the types shown in the parentheses. |
Note: The string must have been created by a call to serialize(). If not, you will receive an error.
exists ( resource ) : booleanChecks if a script exists in the currently loaded packages.
|
resource : | string | The resource name of the Lua script you want to require. |
boolean |
Returns true if the script exists among the loaded resourcers. |
Related sample code
index_offset ( ) : integerThe offset is 0 for 0-based indexing or 1 for 1-based indexing (the default).
|
This function does not accept any parameters. |
integer |
The offset of Lua indices. |
load ( resource ) : fun(nil:any*)?Similar to the standard lua function loadstring(), but loads the script from a Lua script resource instead.
|
resource : | string | The resource name of the Lua script you want to load. |
fun(nil:any*)? |
An anonymous Lua function that causes the script to be run. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
serialize ( data ) : stringSerializes Lua data to an opaque string representation.
|
data : | any(string, number, boolean, table, stingray.Vector3, stingray.Vector3Box, stingray.Matrix4x4, stingray.Matrix4x4Box, stingray.IdString32, stingray.IdString32Box, stingray.IdString64, stingray.IdString64Box) | The Lua object you want to serialize. The any(...) notation indicates that this item may be an instance of any of the types shown in the parentheses. |
string |
The string representation of the data object. |
Other related reference items
set_index_offset ( offset )Set the offset to 0 for 0-based indexing or 1 for 1-based indexing (the default).
|
offset : | integer | The offset of Lua indices. |
This function does not return any values. |
set_temp_byte_count ( s )Sets how much of the buffer for temporary objects created and maintained by the engine is considered in use.
|
s : | integer | The memory size of the temporary objects buffer. |
This function does not return any values. |
If you have a function that uses a lot of temporary objects, you can use this call to reset the temporary buffer and free all of those objects. This function does not export any of those objects to variables that live beyond the length of the function call. These variables might be assigned new values because the system considers them "freed".
Related sample code
set_temp_count ( s )Deprecated: use set_temp_byte_count instead.
|
s : | integer | The memory size of the temporary objects buffer. |
This function does not return any values. |
Sets how much of the buffer for temporary objects created and maintained by the engine is considered in use.
If you have a function that uses a lot of temporary objects, you can use this call to reset the temporary buffer and free all of those objects. This function does not export any of those objects to variables that live beyond the length of the function call. These variables might be assigned new values because the system considers them "freed".
temp_byte_count ( ) : integerReturns the size currently in use in the memory buffer containing temporary objects.
|
This function does not accept any parameters. |
integer |
The memory size of the temporary objects buffer. |
Related sample code
temp_count ( ) : integerDeprecated: use temp_byte_count() instead.
|
This function does not accept any parameters. |
integer |
The memory size of the temporary objects buffer. |
Returns the size currently in use in the memory buffer containing temporary objects.
type_name ( obj ) : stringRetrieves the type name of the specified object.
|
obj : | any | The object whose type you want to retrieve. |
string |
The type name of the object. |
The constants listed in this group can be passed as arguments to stingray.Script.configure_garbage_collection().
ACCEPTABLE_GARBAGE : integerSpecifies the acceptable percentage of available memory that can be spent on garbage, as a number between 0 and 1.
|
A value of 0.1 means 10%. So, if Lua is using 20 MB of memory, it is allowed to use 2 MB of garbage. A higher value here increases your memory usage, but reduces the time required for garbage collection.
The default value is 0.1.
FORCE_FULL_COLLECT_GARBAGE_LEVEL : integerWhen this much of the available memory is occupied by garbage, you can force a full stop to garbage collection.
|
This will stall the game. So, it is generally something you want to avoid, but it can save from crashing if there is a runaway process generating garbage. The default value is 1.0.
MAXIMUM_COLLECT_TIME_MS : integerThe amount of time to spend in garbage collection, in milliseconds, when the maximum garbage value is reached.
|
The default value is 10.
MAXIMUM_GARBAGE : integerSpecifies the maximum percentage of available memory that can be spent on garbage, as a number between 0 and 1.
|
As the amount of garbage approaches this value, more and more time is spent collecting each frame (up to the maximum collect time).
The default value is 0.5.
Other related reference items
MINIMUM_COLLECT_TIME_MS : integerThe minimum time, in milliseconds, spent for garbage collection in each frame (when garbage pressure is low).
|
The default value is 0.5.
Other related reference items