View Source Luex (luex v0.0.2)
Documentation for Luex.
A lot of the types are kept as opaque to allow swichting out lua backends in the future. If you need to it open up, you need to read the source code anyways.
Link to this section Summary
Types
input type for encode/2
A keypath describes a list of keys, to navigate nested tables.
literal type representation of lua boolean values via elixir booleans
represents a lua call, that returned a value and potentially changed the vm state
representation of a lua function.
See Luex.Functions for more information on how to handle this value.
literal type representation of the lua nil value via atom :nil
literal type representation of number values via elixir floats.
literal type representation of lua string values via elixir strings
references a table in a lua virtual machine.
See Luex.Table for more information on how to handle this value.
references a userdata value in a lua virtual machine.
See Luex.Userdata for more information on how to handle this value.
This type can representation any lua type.
options
Functions
run the lua file at path in the given vm.
run a string as lua code in the given vm.
Import an elixir value into a luerl vm. This is function recursively loads lists, keyword lists and maps.
create a new lua virtual machine
is_lua_value checks looks like any representation of a value in a lua vm
an attempt at doing Luerl.encode/2 better.
Link to this section Types
@type encoding_input() :: atom() | binary() | number() | [encoding_input()] | [{encoding_input(), encoding_input()}] | %{required(encoding_input()) => encoding_input()} | {:userdata, any()}
input type for encode/2
@type input_value() :: nil | boolean() | number() | String.t() | Luex.Table.data() | Luex.Functions.input() | {:userdata, any()}
@type keypath() :: [lua_value()]
A keypath describes a list of keys, to navigate nested tables.
For example package.path is a keypath with the elixir representation of ["package", "path"].
@type lua_bool() :: boolean()
literal type representation of lua boolean values via elixir booleans
@type lua_call(result_type) :: %Luex.CallResult{return: result_type, vm: vm()}
represents a lua call, that returned a value and potentially changed the vm state
@type lua_chunk() :: Luex.Records.erl_func() | Luex.Records.funref()
@type lua_fun() :: Luex.Records.erl_mfa() | Luex.Records.erl_func() | Luex.Records.lua_func()
representation of a lua function.
See Luex.Functions for more information on how to handle this value.
@type lua_nil() :: nil
literal type representation of the lua nil value via atom :nil
@type lua_number() :: float()
literal type representation of number values via elixir floats.
@type lua_string() :: String.t()
literal type representation of lua string values via elixir strings
@type lua_table() :: Luex.Records.tref()
references a table in a lua virtual machine.
See Luex.Table for more information on how to handle this value.
@type lua_userdata() :: Luex.Records.usdref()
references a userdata value in a lua virtual machine.
See Luex.Userdata for more information on how to handle this value.
@type lua_value() :: lua_nil() | lua_bool() | lua_string() | lua_number() | lua_table() | lua_userdata() | lua_fun()
This type can representation any lua type.
@type vm() :: Luex.Records.luerl()
@type vm_config() :: {:lua_ext_searcher, [module()]}
options
:ext_searcher: list of modules that implement Luex.ExtModule, used to extend the lua require function.
Link to this section Functions
run the lua file at path in the given vm.
Example
iex> vm0 = Luex.init()
iex> %Luex.CallResult{return: [5]} = Luex.do_file(vm0, "./test/return_5.lua")
run a string as lua code in the given vm.
@spec encode(vm(), encoding_input()) :: lua_call(lua_value())
Import an elixir value into a luerl vm. This is function recursively loads lists, keyword lists and maps.
This is how elixir values are encoded into lua values, by luerl.
graph LR;
ex_nil(nil):::elixir <---> lua_nil(nil):::lua;
ex_bool(boolean):::elixir <--> lua_bool(boolean):::lua;
ex_float(float):::elixir <--> lua_number(number):::lua;
ex_userdata(userdata tuple):::elixir <--> lua_userdata(raw userdata):::lua;
ex_fun(fun/2):::elixir <--> lua_fun(function):::lua;
ex_atom(other atoms):::elixir --> lua_string(string):::lua;
ex_string(String.t):::elixir --> lua_string;
ex_binary(binary):::elixir --"no garantee printable"--> lua_string;
ex_binary <-- lua_string;
ex_map(map):::elixir ---> lua_table(table):::lua;
ex_keyword_list(keyword list):::elixir <---> lua_table
ex_list(other list):::elixir --"index as key"--> lua_table
lua_table --> ex_keyword_list
classDef default stroke-width:3px;
classDef lua stroke:blue;
classDef elixir stroke:#A020F0;Tuples are only allowed as keyword lists items and to indicate userdata.
@spec init() :: vm()
create a new lua virtual machine
is_lua_value checks looks like any representation of a value in a lua vm
@spec load_value(vm(), input_value()) :: lua_call(lua_value())
an attempt at doing Luerl.encode/2 better.