Return array of objects from extern

Monkey Forums/Monkey Programming/Return array of objects from extern

Skn3(Posted 2013) [#1]
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?


AdamRedwoods(Posted 2013) [#2]
looks correct.

"myClass" is never munged since it is extern'ed.
gc_assign looks correct since myClass has Object class as a base, and therefore is gc marked.


Skn3(Posted 2013) [#3]
Thanks :)