Jump to content

Passing Vectors back to UnigineScript


photo

Recommended Posts

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

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:

Link to comment
  • 2 weeks later...

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
  • 2 weeks later...

Hello,

 

Simple way for taking all elements
On С++ side you have CustomStruct array.
Two methods fot it:

getNumCustomStructItems()     // returns number of elements in array
getCustomStructItem(int id)     // returns the specific element

Take 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
×
×
  • Create New...