Jump to content
  • Advertisement
Sign in to follow this  
_Vicious_

Return an array of strings

This topic is 2504 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
That's where reference counting comes in. When the script releases the last reference, the CScriptArray::Release() method takes care of deleting the array. :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!