Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix luerl_new:decode returning incorrect state #191

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Commits on Oct 22, 2024

  1. Fix callbacks not modifying Luerl state

    Callbacks passed to functions implemented in Erlang as `erl_func` in the
    likes were not updating state correctly.
    
    For example, imagine the following Lua program
    
    ```lua
    globalVar = { a = 1 }
    
    function modify_global()
      globalVar['b'] = 2
    end
    
    external_call(modify_global)
    
    return globalVar
    ```
    
    `external_call` is a function implemented in Erlang as
    
    ```erlang
    ExternalFun = fun([Fun], S) ->
        {FunRef, NewState1} = luerl_new:encode(Fun, S),
        io:format("Function ref: ~p~n", [FunRef]),
    
        {ok, Res, NewState2} = luerl_new:call(FunRef, [], NewState1),
        {Res, NewState2}
    end,
    
    State = luerl_new:init(),
    {ok, [], State1} = luerl_new:set_table_keys_dec([<<"external_call">>], ExternalFun, State),
    ```
    
    This program returns
    
    ```erlang
    % Expected
    [[{<<"a">>, 1}, {<<"b">>, 2}]]
    
    % Actual
    [[{<<"a">>, 1}}]]
    ```
    
    - [X] Write a test case that reproduces the problem
    - [ ] Fix the root cause
    davydog187 committed Oct 22, 2024
    Configuration menu
    Copy the full SHA
    3793e8e View commit details
    Browse the repository at this point in the history
  2. port fix to luerl module

    davydog187 committed Oct 22, 2024
    Configuration menu
    Copy the full SHA
    3d81c58 View commit details
    Browse the repository at this point in the history

Commits on Oct 23, 2024

  1. all tests passing

    davydog187 committed Oct 23, 2024
    Configuration menu
    Copy the full SHA
    9e332b6 View commit details
    Browse the repository at this point in the history
  2. fix formatting

    davydog187 committed Oct 23, 2024
    Configuration menu
    Copy the full SHA
    72629cb View commit details
    Browse the repository at this point in the history