Jump to content
  • Advertisement
Sign in to follow this  

Conversion through assignment

This topic is 4730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I've been implementing some scripting using angelscript [and it's really been a pleasure to work with] and have come up to the point that I need to convert between types. Now, this is relatively trivial for defined types, where you can simply register an assignment operator. However, I can't seem to register any assignment operators for the intrinsic types - my test was with "int" but it all works if I register a type "sint" and use that instead. Is it possible to define behaviors for the intrinsic types, or am I doing something wrong? I figure that I can use a conversion function, but it would be nice if I could just use equals. I read in the changelog? that improved implicit and explicit casting is somewhere in the books, but the version that I'm using is [slightly] modified from the original and as such I think it's quite old. I know I really should get a newer version, but the one that I'm using has worked fine so far, so unless there's a reason [that I hit] to upgrade it's on the backburner for the moment. My question is, will updating help me; am I doing something wrong; or should I just make my own conversion functions which aren't registered as assignment operators? Thanks in advance, CJM

Share this post


Link to post
Share on other sites
Advertisement
Just like in C++, AngelScript doesn't allow you to change the operators for intrinsic types. However, C++ does allow you to implement casting operators for your types, this is something that AngelScript still doesn't have but will probably have in the future.

If your version is pre 1.10.1d then I suggest you at least upgrade to that one, as the implicit conversions between intrinsic types was implemented with that version.

Version 2.1.0c, which is the current stable version, doesn't change the way implicit conversions work, but it does provide a more secure environment for your scripts.

For now the best way to convert registered types into intrinsic types is to have either a global function that does the conversion or a method on the type.

Regards,
Andreas

Share this post


Link to post
Share on other sites
Hey,

Thanks, I'll probably just end up either creating a global conversion function which I call manually, or redefining all of the primitive types that I use for all of my functions and putting in assignment operators for those.

[For those who were interested, the reason that I was wanting it was for my console variables, which automagically do other stuff when you change their value, like if you change the data part (an external pointer) of "Var<bool> consoleVisible" to false, the system automatically hides the console and runs all associated stuff. The problem was allowing functions such as "void func(bool)" to access the boolean within the variable. I currently have to use "func(consoleVisible.value())" which is no big issue but it does keep reminding the scriptwriter that it isn't actually a boolean after all.]

Needless to say though, AngelScript is IMO _the best_ scripting system out there [mainly because it's typed and I can more or less put unchanged C code in there and have it work]. Thanks for the reply, and keep up the great work.

CJM

Share this post


Link to post
Share on other sites
I have plans to support get/set function pairs for properties. To the script these will look just like normal properties, but behind the scene they actually call a function instead. But this is probably quite far away yet since there is so many other things that I consider more important.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!