Advertisement

does asOBJ_APP_FLOAT work?

Started by February 03, 2008 02:14 PM
4 comments, last by WitchLord 16 years, 9 months ago
it's not in any of the tests, and the only documentation says it's for float or double types. I tried registering a type as such: engine->RegisterObjectType("Real", sizeof(math::Real), asOBJ_VALUE | asOBJ_APP_FLOAT) and it returns -5 (asINVALID_ARG) (Real is #defined as either double or float depending on how it's compiled) If I change the type to asOBJ_VALUE | asOBJ_POD it compiles, but obviously the Real type doesn't work as it should Thanks again! -Shawn.
It appears that there is a bug in RegisterObjectType() that prevents the type from being registered.


// as_scriptengine.cpp : line 1180else if( flags & asOBJ_APP_FLOAT ){    // Must not set the class flags nor the primitive flag    if( flags & (asOBJ_APP_CLASS             |                    asOBJ_APP_CLASS_CONSTRUCTOR |                    asOBJ_APP_CLASS_DESTRUCTOR  |                    asOBJ_APP_CLASS_ASSIGNMENT  |                    asOBJ_APP_FLOAT) )   //  <-- remove this!        return ConfigError(asINVALID_ARG);}
Advertisement
Excellent, thanks so much. As per the comment I changed it to asOBJ_APP_PRIMITIVE, probably just a copy & paste error by the original author.

-Shawn.
Upon further inspection I don't know if it actually works correctly.

Functions taking double or float don't work with Real types, so I think it's more than just the registration that doesn't work.
Quote: Original post by RsblsbShawn
Upon further inspection I don't know if it actually works correctly.

Functions taking double or float don't work with Real types, so I think it's more than just the registration that doesn't work.


I've never used it myself but IIRC it's treated the same as any other object except when used as a return type. With that in mind you probably need to register some behaviors (cast, assignment, construction, etc.) for special cases.

The asOBJ_APP_xxx flags only tells AngelScript what the real object is for C++, it doesn't affect how AngelScript will treat the object type. These flags are necessary when AngelScript needs to pass a value of the type to a registered function by value (or return by value). They are not used anywhere else.

If you want the "Real" type to work like a float or double you need to register the proper behaviours as Digital_Asphyxia pointed out.

However, you can also wait until I've incorporated the typedef feature that Digital_Asphyxia implemented, which would then let you do what you really want.

Another option is to use a preprocessor pass before adding scripts to AngelScript to substitute all "Real" keywords for "float" or "double". For this you may be interested in looking into Deyja's preprocessor: http://www.omnisu.com/preprocessor.html (Hmm, doesn't seem like the link works any more. Deyja: Are you reading this?)

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