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

sol3 crash/recursion after adding custom type with non-explicit constructors #1618

Open
RDaac opened this issue Aug 7, 2024 · 1 comment

Comments

@RDaac
Copy link

RDaac commented Aug 7, 2024

I'm working with a library that has a variant class with non-explicit constructors for basic types like Variant(bool) and Variant(const char *). After adding sol3 sol_lua_get/push/check() functions for this type, sol operations on basic types, like lua["value"] = "cstring" or sol::stack::push<bool>(boolValue), will favor implicitly converting to the variant type and calling the custom sol_lua_push function over using the built-in operations for the basic types.

Is there a solution or fix for this? The equivalent sol2 implementation using struct pusher worked as expected.

This example recurses and segfaults (g++14, sol 3):

#include <sol.hpp>

struct MyStruct {
    MyStruct(bool val) { value = val; }   // not marked explicit
    bool value;
};


int sol_lua_push(lua_State *L, const MyStruct &v)
{
    // Recurses here instead of calling lua_pushboolean(L, v.value)
    sol::stack::push<bool>(L, v.value);
    return 1;
}

int main()
{
    sol::state lua;
    // Resolves to sol_lua_push(L, MyStruct(true)) instead of lua_pushboolean(L, true),
    lua["value"] = true;  
    return 0;
}
@deadlocklogic
Copy link
Contributor

Using the exact type should work:

int sol_lua_push(sol::types<MyStruct>, lua_State *L, const MyStruct &v) {
    // Recurses here instead of calling lua_pushboolean(L, v.value)
    int amount = sol::stack::push<bool>(L, v.value);
    return amount;
}

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