Lustex v0.2.0 Lustex.Script
lua script execution
This module provides support for executing custom scripts written in the Lua language. These scripts can take on one of the following forms.
- expression: a simple Lua expression that returns a result from the context
- chunk: a script block that ends with a return statement
- function: a script block that defines one or more exported functions
Expressions can be evaluated using eval
, chunks can be executed using
exec
, and functions can be called using call
. Eval/exec accept a
context object that can be used to expose global variables to the script.
Call accepts a positional parameter list that is passed to the function.
Scripts can be pre-compiled using the compile
function. All of the
execution methods support pre-compiled scripts
Link to this section Summary
Functions
calls a Lua function and returns an error tuple on failure
calls a Lua function and throws on failure
generates a Lua-compatible callback for a function
generates a Lua-compatible callback for a module/function
compiles a Lua script block
compiles a Lua script block, throwing on error
evaluates a Lua expression (i.e. “x > 0”) within a context and returns an error tuple on failure
evaluates a Lua expression (i.e. “x > 0”) within a context and raises on failure
executes a Lua script within a context and returns an error tuple on failure
executes a Lua script within a context and raises on failure
Link to this section Types
Link to this section Functions
calls a Lua function and returns an error tuple on failure
calls a Lua function and throws on failure
callback(function :: (... -> any())) :: ([any()] -> [any()])
generates a Lua-compatible callback for a function
callback(module :: module(), function :: (... -> any())) :: ([any()] -> [any()])
generates a Lua-compatible callback for a module/function
compiles a Lua script block
option | description | default |
---|---|---|
globals | map of global variables to assign | %{} |
eval? | evaluate the script to initialze globals? | false |
compiles a Lua script block, throwing on error
eval(script :: String.t(), context :: map()) :: {:ok, any()} | {:error, any()}
evaluates a Lua expression (i.e. “x > 0”) within a context and returns an error tuple on failure
evaluates a Lua expression (i.e. “x > 0”) within a context and raises on failure
executes a Lua script within a context and returns an error tuple on failure
executes a Lua script within a context and raises on failure