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

why when bind function f(int, std::tuple<int, int>) doesn't work? #1480

Open
etorth opened this issue Apr 14, 2023 · 1 comment
Open

why when bind function f(int, std::tuple<int, int>) doesn't work? #1480

etorth opened this issue Apr 14, 2023 · 1 comment

Comments

@etorth
Copy link

etorth commented Apr 14, 2023

code compiled with lua 5.4 and sol 3.3.0

int main()
{
    sol::state lua;
    lua.open_libraries();

    lua.set_function("func1", [](std::tuple<int, int> t)
    {
        std::cout << std::get<0>(t) << ","
                  << std::get<1>(t) << ","

                  << std::endl;
    });

    lua.set_function("func2", [](std::tuple<int, int> t, int k)
    {
        std::cout << std::get<0>(t) << ","
                  << std::get<1>(t) << ","
                  << k              << ","

                  << std::endl;
    });

    lua.set_function("func3", [](int i, std::tuple<int, int> t)
    {
        std::cout << i              << ","
                  << std::get<0>(t) << ","
                  << std::get<1>(t) << ","

                  << std::endl;
    });

    lua.script(R"#(
        func1(   1, 2   )
        func2(   1, 2, 3)
        func3(0, 1, 2   )
    )#");

    return 0;
}

run result:

1,2,
1,2,3,
[sol3] An error occurred and has been passed to an error handler: sol: runtime error: stack index 4, expected number, received no value: not a numeric type that fits exactly an integer (number maybe has significant decimals) (bad argument into 'void(int, std::tuple<int, int>)')
stack traceback:
        [C]: in function 'func3'
        [string "..."]:4: in main chunk

as you can see, func1 and func2 works while func3 not.
Looks param location matters, is this expected?

Thanks,
Etorth

@devgs
Copy link

devgs commented May 16, 2023

Seems like the Lua stack usage tracking gets screwed up. Whenever the tuple is encountered the sol::stack::multi_check is called with the tracking and index that both already account for the processed stack items. Works fine when the tuple is a first item because when it's encountered both values are 0.

If only to know the original author's idea it could be an easy fix. Unfortunately a seemingly simple fix may actually break a lot of unrelated stuff.

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

2 participants