joseph.howell Posted March 15, 2016 Posted March 15, 2016 Hey, I'm trying to create a function in c++ and export it to UnigineScript. I'm trying to follow the "dot" example you have in the documentation. But I can't get it to work after trying lots of things. The function is defined something like this: void someFunc(const vec3 &a, vec3 &b, vec3 &cl) I am exporting it like this: Interpreter::addExternFunction("someFunc", MakeExternFunction(&someFunc)); Then I call it in script like this: vec3 a, b, c; someFunc(a, b, c); But I get this error message: camera_control.h:222: Variable::getExternClassObject(): can't convert vec3 to struct Unigine::Math::vec3 * __ptr64 What am I doing wrong?
ded Posted March 16, 2016 Posted March 16, 2016 Hi, Conversion from "Variable" to "vec3 &" is not defined. There are defined conversions for "vec3" and "const vec3 &". So I suppose signature of your function should be: void someFunc(const vec3 &a, const vec3 &b, const vec3 &c).
joseph.howell Posted March 16, 2016 Author Posted March 16, 2016 Is there no pass by reference then? I wanted to be able to pass a couple of vec3s back out.
ded Posted March 17, 2016 Posted March 17, 2016 Hi,I'm afraid not.There is workaround however: you can pass reference to an instance of extern class. class VectorPair { public: vec3 a; vec3 b; vec3 getA() const { return a; } vec3 getB() const { return b; } }; void foo(const Variable &v) { VectorPair &ret = v.getExternClassObjectRef<VectorPair>(Interpreter::get()); ret.a = vec3(1,2,3); ret.b = vec3(4,5,6); } ... ExternClass<VectorPair> *c = MakeExternClass<VectorPair>(); c->addConstructor(); c->addFunction("getA",&VectorPair::getA); c->addFunction("getB",&VectorPair::getB); Interpreter::addExternClass("VectorPair",c); Interpreter::addExternFunction("foo",MakeExternFunction(&foo));
Recommended Posts