philip.atha Posted October 10, 2014 Share Posted October 10, 2014 Are there any examples of how to return a Unigine::vector<Type> back to UnigineScript? It doesn't appear to work in the way that I would expect. C++ ---MyClass.cpp Unigine::Vector<CustomStruct> &getStruct() { return my_struct; } ---Plugin.cpp ExternClass<MyClass> *my_class= MakeExternClass<MyClass>(); my_class->addConstructor(); my_class->addFunction("getStruct",&MyClass::getStruct); Interpreter::addExternClass("MyClass",my_class); UnigineScript MyClass my_class = new MyClass(); CustomStruct structs[] = my_class.getStruct(); Error: Interpreter::parse_expression_array(): "my_class" is not a user array Link to comment
silent Posted October 10, 2014 Share Posted October 10, 2014 Hi Philip, Any data type may be returned,except for vector, map ,and enum. Also, please check the usage of my_array_vector_generate() in this example: https://developer.unigine.com/en/docs/1.0/cpp_api/usage/arrays?words=my_array_vector_generate,my_array_vector_gener#highlight 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
philip.atha Posted October 19, 2014 Author Share Posted October 19, 2014 So I assume this also applies with structs? I guess I'll just try to explain what I'm trying to do. So I'm calling an SQLite database in C++ and I'm trying to return the data to UnigineScript, but I'm trying to think of the most practical way to do so. I'd prefer to perform operations on the data at the UnigineScript level rather than C++. Link to comment
necris Posted October 27, 2014 Share Posted October 27, 2014 Hello, Simple way for taking all elementsOn С++ side you have CustomStruct array.Two methods fot it: getNumCustomStructItems() // returns number of elements in arraygetCustomStructItem(int id) // returns the specific elementTake elements MyClass my_class = new MyClass(); CustomStruct structs[0] = (); forloop(int i = 0; my_class.getNumCustomStructItems()) { structs.append(my_class.getCustomStructItem(i)); } Also, as stated above, please check the usage of my_array_vector_generate() in this example: https://developer.un...gener#highlight Link to comment
Recommended Posts