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

Variable parameters #193

Open
MeikelLP opened this issue Jan 22, 2025 · 0 comments
Open

Variable parameters #193

MeikelLP opened this issue Jan 22, 2025 · 0 comments

Comments

@MeikelLP
Copy link

According to the lua specs it should be possible to extract dynamic arguments from a special variable called arg.
The following code is not working:

public class ObjWrapper
{
    public string? Function { get; set; }
    public object[]? Arguments { get; set; }

    public void yield(string function, params object[] args)
    {
        Function = function;
        Arguments = args;
    }
}
public class Tests
{
    [Fact]
    public void NeoLua_Params()
    {
        var condition = """
                        function select(...)
                            return obj.yield('select', arg)
                        end
                        select('something', 'something2')
                        """;
        using var lua = new Neo.IronLua.Lua();
        var env = lua.CreateEnvironment();
        var wrapper = new ObjWrapper();
        env["obj"] = wrapper;
        env.DoChunk(condition, "code.lua");
        wrapper.Function.Should().BeEquivalentTo("select");
        wrapper.Arguments.Should().HaveCount(2);
        wrapper.Arguments![0].Should().BeEquivalentTo("something");
        wrapper.Arguments[1].Should().BeEquivalentTo("something2");
    }
}

wrapper.Arguments is [null] but should be ["something", "something2"] probably because arg is not set dynamically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant