I couldn't find this posted anywhere on the forums so thought I would double check I am doing this correctly in a way that is compatible with monkey.
Say I want to return an array of objects created in a cpp file. I have the following native code:
//header
class myClass;
static Array<myClass* > MyFunction();
//classes
class myClass : public Object{
public:
int value;
myClass(int value);
};
myClass::myClass(int value):value(value){}
//functions
static Array<myClass* > MyFunction() {
//create return array with size 2
Array<myClass* > result = Array<myClass* >(2);
//set class objects
gc_assign(result[0],new myClass(123));
gc_assign(result[1],new myClass(999));
//return it
return result;
}
And the following monkey code:
Import "native.cpp"
Extern
Class myClass = "myClass"
Field value:Int
End
Function MyFunction:myClass[]()
Public
Is this correct?
|