-
-
Notifications
You must be signed in to change notification settings - Fork 537
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
Getting compilation error when registering type #1610
Comments
I have this workaround
I can't change the original class, because it's third party comes from Magnum library. Is there any better solution for it ? |
There are basically multiple possible definitions and you need to choose one. Examples: my_vec2_type["x"] = sol::resolve<float& ()>(&MyVec2D::x);
my_vec2_type["y"] = static_cast<float&(MyVec2D::*)()>(&MyVec2D::y); |
I started having this same issue after upgrading to clang 18.1.8 The above fix with I have made a templated wrapper to make it simpler to apply template <typename V, typename C, V C::*Ptr> static auto asLuaPropertyInternal() {
return sol::property(
[](C& type) { return (type.*Ptr); },
[](C& type, const V& val) { (type.*Ptr) = val; }
);
}
template <typename M> struct GetPointerType {
// No need to define this function, may raise a compile or linter warning
template <typename C, typename T> static T getType(T C::*v);
typedef decltype(getType(static_cast<M>(nullptr))) type;
};
template <typename Var, Var var> struct GetVarTraits;
template <typename C, typename T, T C::*Var> struct GetVarTraits<T C::*, Var> {
using klass = C;
};
template <auto Field> static auto asLuaProperty() {
// Figure out the type of the "Field"
using V = typename GetPointerType<decltype(Field)>::type;
// Figure out the class type which this "Field" belongs to
using C = typename GetVarTraits<decltype(Field), Field>::klass;
return asLuaPropertyInternal<V, C, Field>();
}
#define LUA_PROP(Var) asLuaProperty<Var>() And then to use it: my_vec2_type["x"] = LUA_PROP(&MyVec2D::x); Should also work with Visual Studio's MSVC Clang |
@matusnovak I was getting similar problems with some other data types and tried your wrapper. But got compilation errors with msvc
|
I am getting compilation error when I try to register member function x and y for MyVector class.
I think it's happening because of const member function overload.
The error I am getting are
I tried multiple things to make it work, but did not work. Is there any way to register the functions MyVector2::x() ?
The text was updated successfully, but these errors were encountered: