sergey.shandar Posted November 17, 2011 Posted November 17, 2011 Hi, When we add a C++ class to Unigine Script we can also add its functions: class MyObject { public: // size void setSize(const vec3 &s) { size = s; } private: ... }; ExternClass<MyObject> *my_object = MakeExternClass<MyObject>(); my_object->addFunction("setSize",&MyObject::setSize); Is it possible to add a functor? Something like class MyObjectSetSize { public: void operator()(MyObject &this_, const vec3 &s); private: // some additional information here. ... }; ... my_object->addFunctor<void, vec3>("setSize", MyObjectSetSize()); One way to do this, it is to make public the 'Unigine::ExternClass::add_function(...)' function. Are there other ways to add functors without hacking Unigine source code?
frustum Posted November 17, 2011 Posted November 17, 2011 There are three function types which can be added into the ExternClass: class Foo { void foo(int a,int B) { } void foo_const(int a,int B) const { } }; void foo(Foo *foo,int a,int B) { } You can wrap your functor into the static function which receives class pointer as the first argument.
sergey.shandar Posted November 17, 2011 Author Posted November 17, 2011 You can wrap your functor into the static function which receives class pointer as the first argument. The problem with static function is that it can't carry additional information.
Recommended Posts