luerl (luerl v1.5.0)
View SourceLuerl is an implementation of Lua 5.3 written in Erlang. This is the main public API module for interfacing with Luerl.
The LuaState parameter is the state of a Lua VM instance. It must be
created with the init/0 call and be threaded from one call to the
next.
Note that Luerl, following Lua, does do any implicit UTF-8 encoding of
input strings. This means that all strings given as arguments to the
calls or the strings to evaluate with do/3 or do_dec/3 need to
have already been UTF-8 encoded. This can be quite easily do with the
~ or ~b sigils. For example
luerl:do(~b"return 'árvíztűrő tükörfúrógép'", St0)
or
luerl:do(~"return 'árvíztűrő tükörfúrógép'", St0)
Summary
Functions
Runs the garbage collector on a state and returns the new state.
Return a stack trace of the current call stack in the state.
Create a new Lua state which is a fresh Lua VM instance.
Encode/Decode Data functions
Decode a Luerl term into its standard Erlang representation. Note that we have to detect recursive references and generate an error when this occurs.
Decode a list of Luerl terms into their standard Erlang representation. Note that we have to detect recursive references and generate an error when this occurs.
Encode an Erlang term into its Luerl representation if possible.
Encode a list of Erlang terms into their Luerl representations if possible.
Evaluate Code functions
Equivalent to do(Expression, [return], LuaState).
Compile a Lua expression string, evaluate it and return its result, which is NOT decoded, and the new Lua State.
Compile a Lua expression string, evaluate it and return its result, which is is decoded, and the new Lua State.
Equivalent to dofile(FileName, [return], LuaState).
Load and execute the Lua code in the file and return its result which is NOT decoded, and the new Lua State. Equivalent to doing luerl:do("return dofile('FileName')").
Load and execute the Lua code in the file and return its result which is Lua decoded, and the new Lua State. Equivalent to doing luerl:do_dec("return dofile('FileName')").
Function/Method Call functions
Call a function already defined in the state. LuaFuncReaf and Args
are NOT automatically encoded and Result is NOT
automatically decoded.
Call a function already defined in the state. KeyPath is a list of keys to the function. KeyPath and Args are automatically encoded, while Result is automatically decoded.
Call a function already defined in the state. KeyPath is a list of
keys to the function. KeyPath and Args are automatically encoded,
while Result is NOT automatically decoded.
Call the Method in the LuaTable with the Args. The LuaTable,
Method and Args are NOT automatically encoded and the Result
is NOT automatically decoded
Call the Method in the Table with the Args. The Table,
Method and Args are automatically encoded and the Result
is automatically decoded.
Load Code functions
Equivalent to load(LuaChunk, [return], LuaState).
Parse Lua chunk code as string or binary, and return a compiled chunk function.
Load ErlangModule and install its table at KeyPath in the LuaTable
which is NOT automatically Lua encoded.
Load ErlangModule and install its table at KeyPath in the LuaTable
which is automatically Lua encoded.
Parse a Lua file, and return a compiled chunk function.
Calls path_loadfile/4 with Path set the value of LUA_LOAD_PATH and
CompileOptions set to [return].
Equivalent to path_loadfile(Path, FileName, [return], LuaState).
Search down a Path to find the Lua file and return a compiled ('form').
Lua Table Access functions
Get the value of a key in a table. Table, Key are
NOT encoded and the Result is NOT decoded.
Gets a value inside the Lua state. KeyPath is NOT encoded and
Result is NOT decoded.
Gets a value inside the Lua state. KeyPath is automatically encoded
and Result is automatically decoded.
Set the value of a key in a table. Table, Key and Value are
NOT encoded.
Sets a value inside the Lua state. KeyPath and Value are NOT encoded.
Sets a value inside the Lua state. KeyPath and Value are
automatically encoded.
Private Data functions
Delete the private value for Key.
Get the private value for Key.
Puts a private Value under Key that is not exposed to the runtime.
Trace Control functions
Clear the trace function.
Get the current trace data.
Set the trace data.
Set the trace function.
Types
Functions
-spec externalize(LuaState) -> LuaState when LuaState :: luerlstate().
-spec gc(LuaState) -> LuaState when LuaState :: luerlstate().
Runs the garbage collector on a state and returns the new state.
-spec get_stacktrace(LuaState) -> [FuncCall] when LuaState :: luerlstate(), FuncCall :: {FuncName, CallArgs, ExtraInfo}, FuncName :: atom(), ExtraInfo :: [{atom(), term()}], CallArgs :: [term()].
Return a stack trace of the current call stack in the state.
-spec init() -> LuaState when LuaState :: luerlstate().
Create a new Lua state which is a fresh Lua VM instance.
-spec internalize(LuaState) -> LuaState when LuaState :: luerlstate().
Encode/Decode Data functions
-spec decode(LuerlTerm, LuaState) -> Term when LuerlTerm :: luerldata(), Term :: term(), LuaState :: luerlstate().
Decode a Luerl term into its standard Erlang representation. Note that we have to detect recursive references and generate an error when this occurs.
-spec decode_list([LuerlTerm], LuaState) -> [Term] when LuerlTerm :: luerldata(), Term :: term(), LuaState :: luerlstate().
Decode a list of Luerl terms into their standard Erlang representation. Note that we have to detect recursive references and generate an error when this occurs.
-spec encode(Term, LuaState) -> {LuerlTerm, LuaState} when LuerlTerm :: luerldata(), Term :: term(), LuaState :: luerlstate().
Encode an Erlang term into its Luerl representation if possible.
-spec encode_list([Term], LuaState) -> {[LuerlTerm], LuaState} when LuerlTerm :: term(), Term :: term(), LuaState :: luerlstate().
Encode a list of Erlang terms into their Luerl representations if possible.
Evaluate Code functions
-spec do(Expression, LuaState) -> {ok, Result, LuaState} | LuaError | CompileError when Expression :: string(), LuaState :: luerlstate(), Result :: [luerldata()], LuaError :: {lua_error, term(), LuaState}, CompileError :: {error, [term()], [term()]}.
Equivalent to do(Expression, [return], LuaState).
-spec do(Expression, CompileOptions, LuaState) -> {ok, Result, LuaState} | LuaError | CompileError when Expression :: string(), CompileOptions :: [term()], LuaState :: luerlstate(), Result :: [luerldata()], LuaError :: {lua_error, term(), LuaState}, CompileError :: {error, [term()], [term()]}.
Compile a Lua expression string, evaluate it and return its result, which is NOT decoded, and the new Lua State.
-spec do_dec(Expression, LuaState) -> {ok, Result, LuaState} | LuaError | CompileError when Expression :: string(), Result :: [term()], LuaState :: luerlstate(), LuaError :: {lua_error, term(), LuaState}, CompileError :: {error, [term()], [term()]}.
Equivalent to do_dec(Expression, [return], LuaState).
-spec do_dec(Expression, CompileOptions, LuaState) -> {ok, Result, LuaState} | LuaError | CompileError when Expression :: string(), CompileOptions :: [term()], LuaState :: luerlstate(), Result :: [term()], LuaError :: {lua_error, term(), LuaState}, CompileError :: {error, [term()], [term()]}.
Compile a Lua expression string, evaluate it and return its result, which is is decoded, and the new Lua State.
-spec dofile(FileName, LuaState) -> {ok, Result, LuaState} | LuaError | CompileError when FileName :: string(), LuaState :: luerlstate(), Result :: [luerldata()], LuaError :: {lua_error, term(), LuaState}, CompileError :: {error, [term()], [term()]}.
Equivalent to dofile(FileName, [return], LuaState).
-spec dofile(FileName, CompileOptions, LuaState) -> {ok, Result, LuaState} | LuaError | CompileError when FileName :: string(), CompileOptions :: [term()], LuaState :: luerlstate(), Result :: [luerldata()], LuaError :: {lua_error, term(), LuaState}, CompileError :: {error, [term()], [term()]}.
Load and execute the Lua code in the file and return its result which is NOT decoded, and the new Lua State. Equivalent to doing luerl:do("return dofile('FileName')").
-spec dofile_dec(FileName, LuaState) -> {ok, Result, LuaState} | LuaError | CompileError when FileName :: string(), Result :: [term()], LuaState :: luerlstate(), LuaError :: {lua_error, term(), LuaState}, CompileError :: {error, [term()], [term()]}.
Equivalent to dofile_dec(FileName, [return], LuaState).
-spec dofile_dec(FileName, CompileOptions, LuaState) -> {ok, Result, LuaState} | LuaError | CompileError when FileName :: string(), CompileOptions :: [term()], LuaState :: luerlstate(), Result :: [luerldata()], LuaError :: {lua_error, term(), LuaState}, CompileError :: {error, [term()], [term()]}.
Load and execute the Lua code in the file and return its result which is Lua decoded, and the new Lua State. Equivalent to doing luerl:do_dec("return dofile('FileName')").
Function/Method Call functions
Equivalent to call_function(LuaFuncRef, Args, LuaState).
Equivalent to call_function(LuaFuncRef, [], LuaState).
Equivalent to call_function(LuaFuncRef, Args, LuaState).
-spec call_function(LuaFuncRef, Args, LuaState) -> {ok, Result, LuaState} | LuaError when LuaFuncRef :: [luerldata()] | luerldata(), Args :: [luerldata()], LuaState :: luerlstate(), Result :: [luerldata()], LuaError :: {lua_error, term(), LuaState}.
Call a function already defined in the state. LuaFuncReaf and Args
are NOT automatically encoded and Result is NOT
automatically decoded.
-spec call_function_dec(KeyPath, Args, LuaState) -> {ok, Result, LuaState} | LuaError when KeyPath :: [term()], Args :: [term()], LuaState :: luerlstate(), Result :: [term()], LuaError :: {lua_error, term(), LuaState}.
Call a function already defined in the state. KeyPath is a list of keys to the function. KeyPath and Args are automatically encoded, while Result is automatically decoded.
-spec call_function_enc(KeyPath, Args, LuaState) -> {ok, Result, LuaState} | LuaError when KeyPath :: [term()], Args :: [term()], LuaState :: luerlstate(), Result :: [luerldata()], LuaError :: {lua_error, term(), LuaState}.
Call a function already defined in the state. KeyPath is a list of
keys to the function. KeyPath and Args are automatically encoded,
while Result is NOT automatically decoded.
-spec call_method(LuaTable, Method, Args, LuaState) -> {ok, Result, LuaState} | LuaError when LuaTable :: #tref{i :: term()}, Method :: luerldata(), Args :: [luerldata()], LuaState :: luerlstate(), Result :: [luerldata()], LuaError :: {lua_error, term(), LuaState}.
Call the Method in the LuaTable with the Args. The LuaTable,
Method and Args are NOT automatically encoded and the Result
is NOT automatically decoded
-spec call_method_dec(KeyPath, Method, Args, LuaState) -> {ok, Result, LuaState} | LuaError when KeyPath :: [term()], Method :: term(), Args :: [term()], LuaState :: luerlstate(), Result :: [term()], LuaError :: {lua_error, term(), LuaState}.
Call the Method in the Table with the Args. The Table,
Method and Args are automatically encoded and the Result
is automatically decoded.
Load Code functions
-spec load(LuaCode, LuaState) -> {ok, Function, LuaState} | CompileError when LuaCode :: binary() | string(), Function :: #funref{i :: term(), env :: term()}, LuaState :: luerlstate(), CompileError :: {error, [term()], [term()]}.
Equivalent to load(LuaChunk, [return], LuaState).
-spec load(LuaCode, CompileOptions, LuaState) -> {ok, Function, LuaState} | CompileError when LuaCode :: binary() | string(), CompileOptions :: [term()], LuaState :: luerlstate(), Function :: #funref{i :: term(), env :: term()}, CompileError :: {error, [term()], [term()]}.
Parse Lua chunk code as string or binary, and return a compiled chunk function.
-spec load_module(KeyPath, ErlangModule, LuaState) -> LuaState when KeyPath :: [luerldata()], ErlangModule :: atom(), LuaState :: luerlstate().
Load ErlangModule and install its table at KeyPath in the LuaTable
which is NOT automatically Lua encoded.
-spec load_module_dec(KeyPath, ErlangModule, LuaState) -> LuaState when KeyPath :: [term()], ErlangModule :: atom(), LuaState :: luerlstate().
Load ErlangModule and install its table at KeyPath in the LuaTable
which is automatically Lua encoded.
-spec loadfile(FileName, LuaState) -> {ok, Function, LuaState} | CompileError when FileName :: string(), LuaState :: luerlstate(), Function :: #funref{i :: term(), env :: term()}, CompileError :: {error, [term()], [term()]}.
Equivalent to loadfile(FileName, [return], LuaState).
-spec loadfile(FileName, CompileOptions, LuaState) -> {ok, Function, LuaState} | CompileError when FileName :: string(), CompileOptions :: [term()], LuaState :: luerlstate(), Function :: #funref{i :: term(), env :: term()}, CompileError :: {error, [term()], [term()]}.
Parse a Lua file, and return a compiled chunk function.
-spec path_loadfile(FileName, LuaState) -> {ok, Function, FullName, LuaState} | CompileError when FileName :: string(), LuaState :: luerlstate(), Function :: #funref{i :: term(), env :: term()}, FullName :: string(), CompileError :: {error, [term()], term()}.
Calls path_loadfile/4 with Path set the value of LUA_LOAD_PATH and
CompileOptions set to [return].
-spec path_loadfile(Path, FileName, LuaState) -> {ok, Function, FullName, LuaState} | CompileError when Path :: [string()], FileName :: string(), LuaState :: luerlstate(), Function :: #funref{i :: term(), env :: term()}, FullName :: string(), CompileError :: {error, [term()], [term()]}.
Equivalent to path_loadfile(Path, FileName, [return], LuaState).
-spec path_loadfile(Path, FileName, CompileOptions, LuaState) -> {ok, Function, FullName, LuaState} | CompileError when Path :: [string()], FileName :: string(), FullName :: string(), CompileOptions :: [term()], LuaState :: luerlstate(), Function :: #funref{i :: term(), env :: term()}, CompileError :: {error, [term()], [term()]}.
Search down a Path to find the Lua file and return a compiled ('form').
Lua Table Access functions
-spec get_table_key(Table, Key, LuaState) -> {ok, Result, LuaState} | LuaError when Table :: luerldata(), Key :: luerldata(), LuaState :: luerlstate(), Result :: luerldata(), LuaError :: {lua_error, term(), LuaState}.
Get the value of a key in a table. Table, Key are
NOT encoded and the Result is NOT decoded.
-spec get_table_keys(KeyPath, LuaState) -> {ok, Result, LuaState} | LuaError when KeyPath :: [luerldata()], LuaState :: luerlstate(), Result :: luerldata(), LuaError :: {lua_error, term(), LuaState}.
Gets a value inside the Lua state. KeyPath is NOT encoded and
Result is NOT decoded.
-spec get_table_keys_dec(KeyPath, LuaState) -> {ok, Result, LuaState} | LuaError when KeyPath :: [term()], LuaState :: luerlstate(), Result :: term(), LuaError :: {lua_error, term(), LuaState}.
Gets a value inside the Lua state. KeyPath is automatically encoded
and Result is automatically decoded.
-spec set_table_key(Table, Key, Value, LuaState) -> {ok, LuaState} | LuaError when Table :: luerldata(), Key :: luerldata(), Value :: luerldata(), LuaState :: luerlstate(), LuaError :: {lua_error, term(), LuaState}.
Set the value of a key in a table. Table, Key and Value are
NOT encoded.
-spec set_table_keys(KeyPath, Value, LuaState) -> {ok, LuaState} | LuaError when KeyPath :: [luerldata()], Value :: luerldata(), LuaState :: luerlstate(), LuaError :: {lua_error, term(), LuaState}.
Sets a value inside the Lua state. KeyPath and Value are NOT encoded.
-spec set_table_keys_dec(KeyPath, Value, LuaState) -> {ok, LuaState} | LuaError when KeyPath :: [term()], Value :: term(), LuaState :: luerlstate(), LuaError :: {lua_error, term(), LuaState}.
Sets a value inside the Lua state. KeyPath and Value are
automatically encoded.
Private Data functions
-spec delete_private(Key, LuaState) -> LuaState when Key :: term(), LuaState :: luerlstate().
Delete the private value for Key.
-spec get_private(Key, LuaState) -> Value when Key :: term(), Value :: term(), LuaState :: luerlstate().
Get the private value for Key.
-spec put_private(Key, Value, LuaState) -> LuaState when Key :: term(), Value :: term(), LuaState :: luerlstate().
Puts a private Value under Key that is not exposed to the runtime.
Trace Control functions
-spec clear_trace_func(LuaState) -> LuaState when LuaState :: luerlstate().
Clear the trace function.
-spec get_trace_data(LuaState) -> TraceData when LuaState :: luerlstate(), TraceData :: term().
Get the current trace data.
-spec set_trace_data(TraceData, LuaState) -> LuaState when LuaState :: luerlstate(), TraceData :: term().
Set the trace data.
-spec set_trace_func(Function, LuaState) -> LuaState when Function :: fun(), LuaState :: luerlstate().
Set the trace function.