Advertisement

Arrays

Started by May 30, 2006 04:08 PM
1 comment, last by WitchLord 18 years, 6 months ago
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();
Another question regarding arrays:

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

Code:
pEngine->RegisterGlobalFunction("double atof(const String ∈)",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]
Advertisement
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

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

This topic is closed to new replies.

Advertisement