pub struct Engine { /* private fields */ }
Expand description

Start here! An execution engine. Contains information about things like globals, registered types, etc.

Implementations

Creates a new engine.

Creates a new engine with specific debug options.

Engine::new creates an engine with Default debug options, and should generally be preferred unless you’re debugging the language’s internals.

Constructing the engine can fail if the standard library defines way too many methods.

Compiles a script.

Errors

Compiles and starts running a script.

This can be used as a shorthand if you don’t intend to reuse the compiled bytecode.

Errors

See compile.

Calls the provided function with the given arguments.

Errors
  • Error::Runtime - if a runtime error occurs - function isn’t callable or an error is raised during execution
  • Error::TooManyArguments - if more arguments than the implementation can support is passed to the function

Returns the unique ID of a method with a given name and arity.

Note that there can only exist about 65 thousand unique method signatures. This is usually not a problem as method names often repeat. Also note that unlike functions, a method can only accept up to 256 arguments. Which, to be quite frankly honest, should be enough for anyone.

Errors

Calls a method on a receiver with the given arguments.

Note that if you’re calling a method often, it’s cheaper to precompute the method signature into a MethodId by using the method_id function, compared to passing a name+arity pair every single time.

Errors
  • Error::Runtime - if a runtime error occurs - function isn’t callable or an error is raised during execution
  • Error::TooManyArguments - if more arguments than the implementation can support is passed to the function
  • Error::TooManyMethods - if too many methods with different signatures exist at the same time
  • Error::ArgumentCount - if arguments.count() does not match the argument count of the signature

Returns the unique global ID for the global with the given name, or an error if there are too many globals in scope.

The maximum amount of globals is about 16 million, so you shouldn’t worry too much about hitting that limit unless you’re stress-testing the VM or accepting untrusted input as globals.

Errors

Sets a global variable that’ll be available to scripts executed by the engine.

The id parameter can be either an &str or a prefetched global_id.

Errors

Returns the value of a global variable, or nil if it’s not set.

The id parameter can be either an &str or a prefetched global_id.

Errors

Declares a “raw” function in the global scope. Raw functions do not perform any type checks by default and accept a variable number of arguments.

You should generally prefer add_function instead of this.

Note that this cannot accept GlobalIds, because a name is required to create the function and global IDs have their name erased.

parameter_count should reflect the parameter count of the function. Pass None if the function accepts a variable number of arguments. Note that because this function omits type checks you may receive a different amount of arguments than specified.

Errors

Declares a function in the global scope.

Errors

See add_raw_function.

Declares a type in the global scope.

Errors

Starts building a new trait.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.