🎉 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!

Casting pointers

Started by
2 comments, last by WitchLord 19 years, 7 months ago
Can I cast one pointer to another like this: Obj1 *o1 = (Obj2*)o2; Compiling this give the following error: "Expected expression value". This is an option I will very much like to have since I have lots of pointers to derived classes and I need to use pointers to base classes sometimes. Also, if you go and remove all the pointers support (for version 2.0 and above, as stated in another thread) is casting a possibility?
Advertisement
Hi Licu,

Currently AngelScript doesn't support casting of pointers. What you could do is to register a conversion function for the casts that you wish to allow. This function would simply take a pointer as argument and return the same pointer (or possibly do a real C++ cast, which would be necessary for multiple inheritance).

void *ConvertPtr(void *p)
{
return p;
}

engine->RegisterGlobalFunction("CObj1 *ConvObj1(CObj2 *)", asFUNCTION(ConvertPtr), asCALL_CDECL);

Casting will be natively supported in AngelScript as I introduce class inheritance. The changes I will make for AngelScript 2 will make it easier to introduce this feature, as the way objects are handled will be more uniform.

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

Ok, thanks, i was thinking the same thing. The problem is that I don't want to make functions for all the possible casts. Just wanted to use cast as in C. Anyway, all it's ok now that you say it will be natively supported, i can wait for that. Btw, great library, but please make the the lib be outputed in a different folder or name for debug and release. I change them all the time i get a new version. And also it will be usefull to make the WIP project name different than the stable build since i use both of them in the same workspace, stable one for current use and WIP for experimentation and see the new features/syntax. Consider this if other people request it and it's not hard to mantain it with different name, I can change it myself anyway :)

Edit: I see now that you've already changed the output name in WIP6 :)
Thanks. :D

I just keep the different versions in different sub-folders, I don't think it is necessary to use a different output name.

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