Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

Passing pointer to struct


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Gibbon_99   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 March 2004 - 03:28 PM

Hi I have the following typedef struct { float posX; float posY; } _2dPoint; typedef struct { _2dPoint pos; float somethingelse; float anotherThing; } _wayPoint; extern _wayPoint *waypoints; waypoints = malloc(enough space to hold all the data) Q: How do I pass the waypoints pointer to a script, so that within the script I can access: waypoints.pos.posX Thanks very much.

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3444

Like
Likes
Like

Posted 31 March 2004 - 12:36 AM

AngelScript doesn''t yet support the [] operator so I suggest you do the following:


_wayPoint *WayPoint(int index)
{
if( index < 0 || index >= maxWayPoints )
{
GetActiveContext()->SetException("Out of bounds");
return 0;
}

return waypoints[index];
}


Register this function as follows:


engine->RegisterGlobalFunction("waypoint &WayPoint(int index)", asFUNCTION(WayPoint), asCALL_CDECL);


This will allow you to make the following statements in AngelScript:


int n = 10;
waypoint wp;
wp = WayPoint(n);
wp.pos.posX = WayPoint(n+1).pos.posX;
wp.pos.posY = WayPoint(n+2).pos.posY;
WayPoint(n) = wp;



__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS