Problem with registering global behaviour

Started by
0 comments, last by WitchLord 16 years, 6 months ago
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)",
                                      asFUNCTION(AngelValue::assignString),
                                      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)",
                                      asFUNCTION(assignValueToInt),
                                      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)",
                                      asFUNCTION(assignDoubleValueToInt),
                                      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
Advertisement
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 functionint cint(const DoubleValue &in);// In AngelScriptDoubleValue val;int i = cint(val);


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