🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

working with a float* directly

Started by
0 comments, last by WitchLord 17 years, 8 months ago
in c++ i have a function that returns a pointer to an array of floats. how can i register that function to let me return the float* directly so i can manipulate in script the memory buffer without create an asIScriptArray ? i achieved to do this:

// script
int size = 0;
float[] x = object.getData (size);
for (int i = 0; i < size; i++)
{
  x  = 1.0; // this modification is to the temp array returned, not the original float*
  ...
}


but the modifications i make to the x[] are to the temporary asIScriptArray i've created with copied values of the original float* returned by the c++ function getData. i want to work directly with the array:

// script
int size = 0;
float& x = object.getData (size);
for (int i = 0; i < size; i++)
{
  float& y = deReference (x);
  y = 1.0 * i; // this modification is to the original float* array
  x += sizeof("float");
}



is there an hack around to do this (work with directly with type*) or something like ?
Advertisement
I recommend that you register a new type for a float array handle. And then you can register the index operator for this type to access the members. Something like this:

engine->RegisterObjectType("floatarray", sizeof(float*), asOBJ_PRIMITIVE);engine->RegisterObjectBehaviour("floatarray", asBEHAVE_CONSTRUCTOR, "void f()", asFUNCTION(ClearPtr), asCALL_CDECL_OBJLAST);engine->RegisterObjectBehaviour("floatarray", asBEHAVE_INDEX, "float &f(int)", asFUNCTION(FloatAt), asCALL_CDECL_OBJLAST);void ClearPtr(float **ptr){  *ptr = 0;}float &FloatAt(int idx, float **ptr){  return (*ptr)[idx];}


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