Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualAndreas Jonsson

Posted 27 April 2013 - 08:35 AM

It can receive it, but you cannot register functions that explicitly refer to the class, because the class type is not known at the time of registering the function. That's why the application should register an interface that the class will then implement. Like this:

 

 

void ReceiveClass(asIScriptObject *obj)
{
}
 
void ConfigureEngine(asIScriptEngine *engine)
{
   // Register an interface that the classes should inherit from
   engine->RegisterInterface("MyIntf");
 
   // Register the function that will receive the classes
   engine->RegisterGlobalFunction("void ReceiveClass(MyIntf @+)", asFUNCTION(ReceiveClass), asCALL_CDECL);
}

The script class is then implemented like this:
 

// AngelScript
class MyClass : MyIntf
{
}
 
void main()
{
   MyClass c;
 
   // Pass the object to the application
   ReceiveClass(c); 
}


#1Andreas Jonsson

Posted 27 April 2013 - 08:34 AM

It can receive it, but you cannot register functions that explicitly refer to the class, because the class type is not known at the time of registering the function. That's why the application should register an interface that the class will then implement. Like this:

 

void ReceiveClass(asIScriptObject *obj)
{
}
 
void ConfigureEngine(asIScriptEngine *engine)
{
   // Register an interface that the classes should inherit from
   engine->RegisterInterface("MyIntf");
 
   // Register the function that will receive the classes
   engine->RegisterGlobalFunction("void ReceiveClass(MyIntf @+)", asFUNCTION(ReceiveClass), asCALL_CDECL);
}
/code]
 
The script class is then implemented like this:
 
[code]
// AngelScript
class MyClass : MyIntf
{
}
 
void main()
{
   MyClass c;
 
   // Pass the object to the application
   ReceiveClass(c); 
}

 

If you do not want to use interfaces like the above, then you could use the script any or script handle add-ons that are generic containers and can hold any type.

 

Regards,

Andreas


PARTNERS