Permalink
Browse files

luerl_eval:call/3: Support the 5-elements function tuple

This fixes the case where a reference to a function is returned by a Lua
code and executed from an Erlang function.

Here's a code sample:
    % Load Lua script.
    {ok, Chunk} = luerl:loadfile("callback.lua"),
    % Run the script: it returns a reference to a function.
    St = luerl:init(),
    {[Fun | _], St1} = luerl:do(Chunk, St),
    % Execute the returned Lua function.
    luerl:call(Fun, [], St1).

The callback.lua script could be:
    function callback()
        print("It works!")
    end
    return callback
  • Loading branch information...
1 parent a08c5f8 commit 397a247eaab372ee070b6cc3fe4f3daaeafa72b5 @dumbbell dumbbell committed Sep 26, 2012
Showing with 4 additions and 0 deletions.
  1. +4 −0 src/luerl_eval.erl
View
@@ -367,6 +367,10 @@ call({functiondef,L,Ps,B}, Args, St0) ->
{Ret,St2} = functioncall(Func, Args, St1),
%% Should do GC here.
{Ret,St2};
+call({function,_,_,_,_}=Func, Args, St0) ->
+ {Ret,St1} = functioncall(Func, Args, St0),
+ %% Should do GC here.
+ {Ret,St1};
call({function,_}=Func, Args, St0) ->
{Ret,St1} = functioncall(Func, Args, St0),
%% Should do GC here.

0 comments on commit 397a247

Please sign in to comment.