Return an array of strings

Started by
11 comments, last by _Vicious_ 12 years, 2 months ago
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.
Advertisement
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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Found it, thanks!
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

ah, you're doing 'delete this;' there :) nasty!
Hm.. I need your help once again, Andreas smile.png
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.
Hm.. The obj pointer seems to be pointing at the wrong address after all.
Change the code to read:
*((Element **)arr->At(n++)) = *it;
instead of
arr->InsertAt( n++, *it );
and it somewhat worked, but that's weird anyway...

This topic is closed to new replies.

Advertisement