Type casting
Alright, in my code, I have a void *data, and this data variable will hold all sorts of different entities in it. But, I need to get that data into AngelScript. So I was wondering how I should go about doing that... In C++ it's just a type cast, but angel doesn't really have pointers like that, right?
thanks
Correct.
I recommend you register a new type to hold the pointer for this generic data. That way you will be able to control from the application what happens to the pointer.
Something like this:
Now you will be able to register functions that take or return this new type. To C++ the type is a normal void* pointer, but to AngelScript it is a special object type that cannot be mixed with other types.
If you want, you can also have AngelScript perform reference counting for you. For this you'll need to register the asBEHAVE_ADDREF and asBEHAVE_RELEASE behaviours.
To retrieve data from the new type, you'll have to register functions that take a 'data' argument and returns the requested data from it.
Regards,
Andreas
I recommend you register a new type to hold the pointer for this generic data. That way you will be able to control from the application what happens to the pointer.
Something like this:
void ClearPtr(void **ptr){ *ptr = 0;}void RegisterDataType(){ engine->RegisterObjectType("data", sizeof(void*), asOBJ_PRIMITIVE); engine->RegisterObjectBehaviour("data", asBEHAVE_CONSTRUCT, asFUNCTION(ClearPtr), asCALL_CDECL);}
Now you will be able to register functions that take or return this new type. To C++ the type is a normal void* pointer, but to AngelScript it is a special object type that cannot be mixed with other types.
If you want, you can also have AngelScript perform reference counting for you. For this you'll need to register the asBEHAVE_ADDREF and asBEHAVE_RELEASE behaviours.
To retrieve data from the new type, you'll have to register functions that take a 'data' argument and returns the requested data from it.
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
Popular Topics
Advertisement