Jump to content
  • Advertisement
Sign in to follow this  
gilad_novik

Arrays

This topic is 4520 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

I have a string type registered, and some functions to create an array of strings. I want to add a new method for arrays (general or specific type). I'm not sure it's possible. Can I use the following syntax: pEngine->RegisterObjectMethod("string[]", "void dump()", ...); I want to be able to use the following script: string[] a; createArray(a); a.dump(); Will it work? In addition, is there a way to create a function for ALL types? so every array can call it? string[] a; int[] i; double[] d; a.dump(); i.dump(); d.dump();

Share this post


Link to post
Share on other sites
Advertisement
Another question regarding arrays:

Script:
String[]@ list=createArray();
double dValue;
dValue=atof(list[0]);

Code:
pEngine->RegisterGlobalFunction("double atof(const String &in)",asFUNCTION(StringToDouble),asCALL_CDECL);

I get an assertion inside as_compiler.cpp(line 6107)
assert(ctx->type.dataType.IsPrimitive());

What am I doing wrong?

[EDITED]
I've tried to remove the @ (now it's: String[] list=createArray();) and it works. But I assume it copies the array. If I want to avoid it (suppose I have a big array, I don't want it to be copied multiple times), should I define AddRef/Release for an array type?

[Edited by - gilad_novik on May 30, 2006 5:08:10 PM]

Share this post


Link to post
Share on other sites
Quote:

I want to add a new method for arrays (general or specific type).


It might work by calling RegisterObjectMethod(), but it is not officially supported, and may stop working in future releases.

Quote:

In addition, is there a way to create a function for ALL types? so every array can call it?


No, there is not. For that you would have to modify the library itself.

I have plans on allowing registration of variable function parameters though, just like how the 'any' type current is able to accept any object handle. That could be used to allow the registration of functions that will work for any type. But I'm not sure when that will be done.

Quote:

I get an assertion inside as_compiler.cpp(line 6107)
assert(ctx->type.dataType.IsPrimitive());


This is likely a bug in AngelScript. The very least you should have received an error message, instead of hitting the assert(). I'll make some tests and fix this.

Regards,
Andreas

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!