-
Notifications
You must be signed in to change notification settings - Fork 142
0.5 Luerl examples
csrl edited this page Feb 19, 2023
·
4 revisions
To run the examples, do make
and then start the Erlang command line with erl -pa ./ebin
.
Don't be shocked by the very long dump following each function call.
At the command line you are seeing the Lua State dumped, that is returned by these calls:
luerl:do("print(\"Hello, Robert!\")", luerl:init()).
luerl:dofile("./examples/hello/hello.lua", luerl:init()).
EmptyState = luerl:init(),
{ok, Chunk, State} = luerl:load("print(\"Hello, Chunk!\")", EmptyState),
{_Ret, _NewState} = luerl:do(Chunk, State).
{Res,State1} = luerl:call_function([table,pack], [<<"a">>,<<"b">>,42], State0)
executes the call table.pack("a", "b", 42)
in State0
. E.g.:
{Res,State1} = luerl:call([table,pack], [<<"a">>,<<"b">>,42]),
io:format("~p~n",[Res]).
{Res,State1} = luerl:call_method([g,h,i], [<<"a">>,<<"b">>,42], State0)
executes the call g.h:i("a", "b", 42)
in State0
.
State1 = luerl:set_table([inc], fun([Val], State) -> {[Val+1], State} end)
the method can be called like this:
luerl:do(<<"print(inc(4))">>, State1)
For more information see the examples directory:
./hello.erl
is very brief while examples/hello/hello2.erl
offers a comprehensive list on how use the individual interface functions.
You can build and run these samples with:
make examples