pub struct LuaMachine<'a> { /* private fields */ }
Expand description

Virtual machine that executes Lua code

Basic usage

  1. A new virtual machine can be created with LuaMachine::new.
  2. Use LuaMachine::load_stdlib_sealed to load a sealed version of the Lua standard library; that is a modified version which does not allow breaking out of the sandbox. Alternatively, a full version of the standard library can be loaded with LuaMachine::load_stdlib, which, for example, can be used to load further dependencies, and then be sealed afterwards with LuaMachine::seal. Note, however, that this may introduce security vulnerabilites depending on which libraries have been loaded or how the state has been modified prior to calling seal.
  3. Set resource limits with LuaMachine::set_memory_limit and LuaMachine::set_execution_limit, if desired.
  4. Use the API provided by the sandkiste crate to compile and execute Lua programs. For a concrete example using Lua, see the top-level module documentation of sandkiste_lua.

Lifetimes

Lifetime argument 'a is a lower bound for closures passed to the Lua machine. It can be inferred automatically.

Implementations

Create a bare Lua machine

Retrieve pointer to lua_State

Assert that Lua stack is empty

Set limit for executed instructions

Set memory limit

Load standard library

Load sealed version of standard library

Remove certain parts of standard library to seal machine as sandbox

Create empty table

Pop error value from Lua stack and convert into String

If status != LUA_OK, pop error value from Lua stack and convert into MachineError

Same as LuaMachine::pop_error but also extract traceback (requires cmach_lua_errmsgh to be used during lua_pcall)

Convert value on Lua stack into LuaDatum

NOTE: requires some free space on Lua stack for operation

Pop value from Lua stack and convert into LuaDatum

NOTE: requires some free space on Lua stack for operation

Push LuaReference on top of Lua stack

Push binary data on top of Lua stack

NOTE: requires some free space on Lua stack for operation

Push string on top of Lua stack

NOTE: requires some free space on Lua stack for operation

Push LuaDatum on top of Lua stack

NOTE: requires some free space on Lua stack for operation

Trait Implementations

Create a Machine::Datum representing a callback (which invokes the func closure)

Same as Callback::callback but expects a fixed number of arguments

Same as Callback::callback but expects a minimum number of arguments

Same as Callback::callback but expects exactly one argument

Same as Callback::callback but expects exactly two arguments

Same as Callback::callback but expects exactly three arguments

Same as Callback::callback but expects exactly four arguments

Same as Callback::callback but expects exactly five arguments

Compiles code, returns the compiled function or a compilation error Read more

Compiles code, returns the compiled function or a compilation error Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Get global variable

Set global variable

Create datum that is an empty array

Create datum that is an array

Type of modules and sub-modules

Open a module (create if non-existent)

Create datum that is an empty string map

Create datum that is a string map

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Data type representing values passed to or returned from machine

Function (for example returned by Compile::compile) which can be executed by the machine Read more

A LuaMachine is only equal to itself

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

A LuaMachine is only equal to itself

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.