Request for examples regarding an array of handle and passing an array as an argument
Hello,
First of all, I'm just starting using AngelScript. And I have to say, it is really easy to use and the C++ syntax make it much more natural to code for me than Lua :)
However, I still find the documentation somewhat lacking. It wasn't that easy for me to get start, since there aren't really a tutorial to get me start. The one in the documentation didn't tell me to include the helper classes in the addon, so that took me a while to realize what I need to do.
Anyway, my question is that, I see that the documentation said it is possible to make an array of handle or a handle to an array. However, there is no really any example on how to declare something like that.
Another question is , I have a C++ function that take a pointer to a struct as one of its argument. This allow me to pass an array into such function. However, I don't know how to export such function to AngelScript. To make it easier to understand, the function looks like this.
Vector3D[] vector[6];
DrawImageToPolygon3D(texture, vector);
What should I do in this situation?
Thank you in advance! :)
EDIT : I've tried MyClass@[] test_array(1000) and it seems to work! If I understand correctly, this is the "array of handle" right? What about a "handle to array"?
[Edited by - hima on August 24, 2009 4:30:43 AM]
Hi hima,
glad you like AngelScript so far. I'll try to use your feedback about the manual to improve it.
To declare an array of handles, you use the form you discovered:
To declare a handle to an array, you put the @ after the brackets:
Arrays in C++ rely on the user knowing the size of the array. This is not safe in a scripted environment where the engine has to guarantee a sandbox environment even when the script writer isn't experienced. For that reason there is no direct match between arrays in the script and C++ arrays accessed through a simple pointer.
In your example, you had best write a wrapper to your DrawImageToPolygon, to use an array object rather than a direct C++ pointer. If you decide to use the built-in array object for this, then your wrapper might look like this:
The built-in array type is a generic container designed to be able to hold any data with the same implementation, thus it doesn't have the best of performance. If performance is of concern you should look into overriding the built-in array for the array types you use the most. This is done by registering the object type normally, except that the name of the type should be "Vector3D[]".
You may also want to look into the template array add-on.
Regards,
Andreas
glad you like AngelScript so far. I'll try to use your feedback about the manual to improve it.
To declare an array of handles, you use the form you discovered:
MyClass@[] arrayOfHandles;
To declare a handle to an array, you put the @ after the brackets:
MyClass@[]@ handleToArrayOfHandles;int[]@ handleToArrayOfIntegers;
Arrays in C++ rely on the user knowing the size of the array. This is not safe in a scripted environment where the engine has to guarantee a sandbox environment even when the script writer isn't experienced. For that reason there is no direct match between arrays in the script and C++ arrays accessed through a simple pointer.
In your example, you had best write a wrapper to your DrawImageToPolygon, to use an array object rather than a direct C++ pointer. If you decide to use the built-in array object for this, then your wrapper might look like this:
void DrawImageToPolygon3D_wrap(int texture, asIScriptArray *array){ // Copy the vectors from the script array to a linear buffer std::vector<Vector3D> vec; vec.resize(array->GetElementCount()); for( unsigned int n = 0; n < vec.size(); n++ ) { vec[n] = *(Vector3D*)array->GetElementPointer(n); } // Call the original function DrawImageToPolygon3D(texture, &vec[0]);}
The built-in array type is a generic container designed to be able to hold any data with the same implementation, thus it doesn't have the best of performance. If performance is of concern you should look into overriding the built-in array for the array types you use the most. This is done by registering the object type normally, except that the name of the type should be "Vector3D[]".
You may also want to look into the template array add-on.
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
Thank you so much for your reply! I finally got it to work by wrapping it using array object like the example you suggested :D
However, I'm not quite sure how to register the array. Should it be ref type or value type?
Also, is there any addon that add a link-list to AngelScript?
Thank you in advance!
However, I'm not quite sure how to register the array. Should it be ref type or value type?
Also, is there any addon that add a link-list to AngelScript?
Thank you in advance!
If you're going to override the built-in array type, then I suggest you use asOBJ_REF. Otherwise it may be a bit confusing to the script writer when he can use handles for some array types and not for others.
I haven't created an add-on for registering a linked list. If someone would like to provide one though, I'll gladly add it to the SDK.
I haven't created an add-on for registering a linked list. If someone would like to provide one though, I'll gladly add it to the SDK.
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
Popular Topics
Advertisement