Hello,
is it possible for application registered (or script) function or method to return an array of elements? For example, I want to be able to split a string with a delimiter and return an array of strings as the result. I'm using the array addon for handling arrays, if that matters.
Return an array of strings
Yes, it is possible. In fact, this is already implemented as part of the string add-on.
You'll find it in the add_on/scriptstrstring/scriptstdstring_utils.cpp.
Regards,
Andreas
You'll find it in the add_on/scriptstrstring/scriptstdstring_utils.cpp.
Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
Hm, may I ask whether there's any special reason the aforementioned example uses generic calling convention?
The only reason is that I simply preferred implementing the function with the generic calling convention directly instead of implementing it as a normal function and then providing a generic wrapper for it.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
btw, that example does 'new CScriptArray' so there's supposed to be a corresponding 'delete' somewhere for the created object, am I correct? I bet the GC won't do this on its own..
That's where reference counting comes in. When the script releases the last reference, the CScriptArray::Release() method takes care of deleting the array.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
Hm.. I need your help once again, Andreas
I'm trying to implement a method that returns an array of object handles, here's the code:
I don't see anything wrong with the function itself, however Angelscript crashes while attempting to execute the AddRef method of the Element * object:
http://www.foopics.c...2379582de5a69ff
The function registers and the script compiles just fine. The 'obj' and 'f' pointer in CallObjectMethod seem to be pointing to proper locations.. I'm lost here.
I'm trying to implement a method that returns an array of object handles, here's the code:
ASElementsArray *Element_GetElementsByTagName( Element *elem, const asstring_t *tag )
{
ElementList elements;
elem->GetElementsByTagName( elements, ASSTR(tag) );
ASElementsArray *arr = UI_Main::Get()->getAS()->createArray( elements.size(), elementsArrayType );
unsigned int n = 0;
for( ElementList::iterator it = elements.begin(); it != elements.end(); it++ ) {
arr->InsertAt( n++, *it );
}
return arr;
}
I don't see anything wrong with the function itself, however Angelscript crashes while attempting to execute the AddRef method of the Element * object:
http://www.foopics.c...2379582de5a69ff
The function registers and the script compiles just fine. The 'obj' and 'f' pointer in CallObjectMethod seem to be pointing to proper locations.. I'm lost here.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement