enrique.trilles Posted September 2, 2019 Share Posted September 2, 2019 (edited) Hi. I've been reading the documentation on class and data export at "Programming/C++/C++ Usage Examples/ *** Export", but this specific case eludes me: How can I call an UnigineScript function that has a custom struct (Correctly defined and exported) as argument? (Example below) /////:::::::::::: UNIGINESCRIPT ::::::::::::::::::::::::::::::::::::: void myUnigineFunction(MyClass argument){ /* Do stuff */ } /////:::::::::::: CPP ::::::::::::::::::::::::::::::::::::::::::::::: using namespace Unigine; class MyClass { public: int var1, var2; MyClass() {/**/} ~MyClass() {/**/} static void RegisterMyClass(){ // Function called on main, before Engine definition and Engine->main call ExternClass<MyClass>* exported = MakeExternClass<MyClass>(); exported->AddConstructor(); exported->AddFunction("function1", &MyClass::Function1); exported->AddFunction("function2", &MyClass::Function2); Interpreter::AddExternClass("MyClass", exported); } void Function1() {/**/} void Function2() {/**/} }; // --------- void OneGenericFunction() { MyClass data; // data.var1 = something; // data.var2 = somethingelse; /******/ // <-- How should I do this? Engine::get()->runWorldFunction(Variable("myUnigineFunction"), Variable(data)); } EDIT: I assume I have to play around with TypeInfo and/or the interpreter, but i had no luck. Any help on the matter will be much appreciated. Thanks for your time. Edited September 2, 2019 by enrique.trilles Link to comment
morbid Posted September 2, 2019 Share Posted September 2, 2019 Hello Enrique, Which SDK version is this? Thanks. How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
cash-metall Posted September 2, 2019 Share Posted September 2, 2019 (edited) Hello! You did everything right! Interpreter *world = (Interpreter*)Engine::get()->getWorldInterpreter(); if (world) { MyClass data(3,2); Unigine::Variable v(world, TypeInfo(TypeID<MyClass*>()), &data); // through type faster // Unigine::Variable v(world,"MyClass", &data); // so it works too Engine::get()->runWorldFunction(Variable("myUnigineFunction"), v); } https://developer.unigine.com/en/docs/2.9/code/cpp/usage/classes#memory_management Edited September 2, 2019 by cash-metall added link to doc Link to comment
enrique.trilles Posted September 2, 2019 Author Share Posted September 2, 2019 Ah, now I see. I was trying to get the interpreter pointer incorrectly. Thanks for the help! [I'm using at the moment 2.8 version btw] Link to comment
Recommended Posts