Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

Casting pointers


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
3 replies to this topic

#1 Licu   Members   -  Reputation: 128

Like
0Likes
Like

Posted 31 October 2004 - 05:44 AM

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?

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3334

Like
0Likes
Like

Posted 31 October 2004 - 01:08 PM

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

#3 Licu   Members   -  Reputation: 128

Like
0Likes
Like

Posted 01 November 2004 - 01:22 AM

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 :)

#4 Andreas Jonsson   Moderators   -  Reputation: 3334

Like
0Likes
Like

Posted 01 November 2004 - 04:32 AM

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




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