Skip to content

ScriptEngine

Hyomoto edited this page Jun 24, 2021 · 13 revisions
Jump To Go Back Methods Variables

ScriptEngine( )

Implements: Struct

The script engine can be used to execute scripts and handle coroutines. While scripts can be executed manually, the script engine will handle the more complex yield states of scripts by calling update(). When a script is executed, if it returns a yield it will be placed into a queue that will be executed each frame until it resolves.

engine	= new ScriptEngine();
engine.load_async("txt", "", false )
Output: Loads all .txt files in the included files as scripts.

Methods

Jump To top execute update allow_global set_global bind bind_safe load_async load

execute( source, *args... )

Returns: mixed

Throws: InvalidArgumentType

Name Type Purpose
source mixed A script or string to execute
*args... mixed Arguments to pass into the script

Calls for a script or function to be executed and returns the result. If the source is a Script and calls a yield, it will be executed each frame until it resolves. If the source can not be resolved into a script or function InvalidArgumentType will be thrown.


update( )

Name Type Purpose
None

Calls for the engine to execute any scripts that have yielded.


allow_global( allow )

Name Type Purpose
allow bool If false, will not allow global access

If allow is not false, the engine global scope will be reachable from executed scripts. By disallowing this, only the script's local function scope can be used.


set_global( struct )

Name Type Purpose
struct struct A struct to use for global space

Allows you to define the global space that is passed into scripts when they are executed. This space is persistent unless overwritten.


bind( name, value )

Name Type Purpose
name string The name to assign the function to
value method The function to assign

Binds the given value to name. This value will be accessible to scripts that are executed from the engine. You can bind values, functions, methods and Scripts.


bind_safe( name, value )

Name Type Purpose
name string The name to assign the function to
value method The function to assign

Used to bind script functions to the engine when FAST_SCRIPT_PROTECT_FUNCTIONS is true. Because of how GMS looks up functions internally, a user could reach unintended functions in GMS by simply executing numbers as functions. This will wrap the function that reference in ScriptFunctionWrapper which flags this value as acceptable for function calls.


load_async( source )

Throws: InvalidArgumentType, FileNotFound

Name Type Purpose
source InputStream A input stream

Loads the given stream of files. Execution is yielded if the load process takes too long. If source is not an InputStream, InvalidArgumentType is thrown.


load( filename, *as )

Throws: InvalidArgumentType, FileNotFound

Name Type Purpose
filename string The name of the file
*as string optional: The name to load the file as

Loads the given filename as a script. If as is not provided, the script will be loaded using the name of the file. If filename or as is not a string, InvalidArgumentType will be thrown. If the file does not exist, FileNotFound will be thrown.


Variables

Jump To top
Name Type Initial Purpose
Coroutines undef new LinkedList() No description.
Variables undef {} No description.
Global undef undefined No description.
Async undef undefined No description.
Clone this wiki locally