Sign in to follow this  

Problem with registering global behaviour

Recommended Posts

I am trying to register automatic conversion (assignment) from abstract Value class to integer, but it doesn't seem to work. Non-abstract class does just fine and I can register other functions easily for Value, just not the global behaviour. The global behaviour registration works fine with DoubleValue, a non-abstract class derived from Value. The only difference between these two that I have been able to find is that Value is abstract. But the function that does the assignment is static, so the fact that Value is abstract should definitely not break anything or probably should do so in compilation time, not later. I don't seem to get any error messages from AngelScript callback either, although it is registered and works in other cases. I extracted some of the code:
// Abstract baseclass
class Value {
  virtual double getIntValue() = 0;

int assignValueToInt(Value* value) {
  return value->getIntValue();

// Subclass of value
class DoubleValue : public Value {
  double getDoubleValue() { return 0.0; }

int assignDoubleValueToInt(DoubleValue* value) {
  return value->getIntValue();

// Regist
r = engine->RegisterObjectType("Value", sizeof(Value), asOBJ_CLASS_CA); assert( r >= 0 );

// Register dummy constructor that gives an error etc...

// This works fine
r = engine->RegisterObjectBehaviour("String", asBEHAVE_ASSIGNMENT,
                                      "String& f(const Value &in)",
                                      asCALL_CDECL_OBJFIRST); assert( r >= 0 );

// Doesn't work, assert aborts, return code is -5 (invalid argument)
	r = engine->RegisterGlobalBehaviour(asBEHAVE_ASSIGNMENT,
                                      "int f(const Value &in)",
                                      asCALL_CDECL); assert( r >= 0 );

r = engine->RegisterObjectType("DoubleValue", sizeof(DoubleValue), asOBJ_CLASS_CA); assert( r >= 0 );

// Works just fine
r = engine->RegisterGlobalBehaviour(asBEHAVE_ASSIGNMENT,
                                      "int f(const DoubleValue &in)",
                                      asCALL_CDECL); assert( r >= 0 );
I don't even have any more ideas where the problem might be... I am probably overlooking something, but I have tried to find the problem for two days by now, so any help is appreciated. Mr Jones

Share this post

Link to post
Share on other sites
What you're trying to do isn't supported yet.

Assignment behaviours aren't allowed to be registered as global behaviours. I'll have to investigate why AS is accepting it for the DoubleValue, it shouldn't have.

Adding support for cast behaviours is a high priority to me, which will allow you to do what you want. But for now the best thing you can do is to register a normal function to do what you want, e.g:

// C++ registered function
int cint(const DoubleValue &in);

// In AngelScript
DoubleValue val;
int i = cint(val);


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this