Lua with CML

Started by
2 comments, last by Matt328 7 years, 10 months ago

I'm having trouble binding pretty much any classes from CML (configurable math library) to Lua. Due to them being such a tangled mess of templates and macros, I can't seem to find the function signatures for the overloaded operator functions. I'm trying to use LuaBridge right now to register the cml::vector3f::operator+= function, and since there are so many overloads, I think I have to cast the address of the function to the function signature I want it to bind. Currently I'm trying:


.addFunction("__add", (Vector3& (*)(const Vector3&))&Vector3::operator+=)

(I have Vector3 typedef'ed to cml::vector3f) but that produces:


Address of overloaded function 'operator+=' does not match required type 'cml::vector<float, cml::fixed<3, -1> > &(const cml::vector<float, cml::fixed<3, -1> > &)'

I'm just about ready to punt on scripting altogether and just do everything in C++.

Advertisement

I would try defining the proper function type you need, and assigning &Vector3::operator+= to a temporary of that type, to use in addFunction().

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

That is what I hve been trying but poking around in the dark at the end of a very long day trying to guess the function signature had been less than effective. Even when I use auto, the compiler can't figure it out I guess because there are multiple overrides of the operator+= function. I think that is why .addFunction is complaining and making me explicitly cast to one of them. I've also tried using decltype to determine the signature, but with the same results.

I was also unable to get operator[] to work and I now realize for the same reason. I am able to define a helper struct and delegate to the original object but I'd rather not have to do that especially if it is as trivial as figuring out what the compiler thinks the function signatures are.

I'm using clang with C++14 support if that helps.

I got this figured out, I was really close, but missing the signature for a function pointer to member is different than a function pointer to a free function.


.addFunction("__add", (Vector3&(Vector3::*)(const Vector3&))&Vector3::operator+=)

I had * instead of Vector3::* in the middle of the function pointer type.

This topic is closed to new replies.

Advertisement