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

If fewer parameters than required are passed when calling a function in Lua, it will crash. #1647

Closed
blackchicken20 opened this issue Nov 16, 2024 · 1 comment

Comments

@blackchicken20
Copy link

this is test code:
use: vs2019 msvc C++14 Debug
The expected behavior is that the exception can be caught by sol and handled properly.
It seems that issue #916 is similar to the problem I'm encountering. However, I'm currently using the latest default branch, and the problem still persists.

class Vec2
{
public:
    Vec2() 
        : x(0.f), y(0.f)
    {

    }
    Vec2(float x, float y)
        : x(x), y(y)
    {

    }
    ~Vec2() 
    {

    }

    float x;
    float y;
};

Vec2 TestFn(Vec2 A, Vec2 B)
{
    std::printf("A:%.2f %.2f\n", A.x, A.y);
    std::printf("B:%.2f %.2f\n", B.x, B.y);
    return { 1.0f,2.0f };
}

Vec2 Vector2(float x,float y){
    return { x, y };
}

sol::table math_table = lua.create_table();
env["Math"] = math_table;
math_table.set_function("Vector2", Vector2);
math_table.set_function("TestFn", TestFn);
auto vec2_user_type = lua.new_usertype<Vec2>("Vector2",
        "x", &Vec2::x,
        "y", &Vec2::y);
local A = Math.Vector2(1, 1)
local B = Math.Vector2(2, 2)
print(Math.TestFn(A).x)
bug
@blackchicken20
Copy link
Author

When I switched to sol3's main branch, the issue was resolved. Great work by sol3.

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