Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

asIScriptGeneric with object method possible?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 thd.MM   Members   -  Reputation: 208

Like
0Likes
Like

Posted 20 October 2012 - 03:18 PM

I'm trying to register a variable parameter method like in this example: http://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_var_type.html
but in an object.

r = engine->RegisterObjectMethod("JGizmo", "void KeepInBounds( ?&in )",
asMETHOD( JGizmo, call),
asCALL_GENERIC); assert( r >= 0 );

but it fails to register with code: asWRONG_CALLING_CONV

with asCALL_THISCALL it just crashes when accessing the asIScriptGeneric object.

Is this possible at all for object methods?

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9541

Like
0Likes
Like

Posted 20 October 2012 - 03:29 PM

Function pointers registered with asCALL_GENERIC must have the type void (*)(asIScriptGeneric *) this means that they cannot be member functions.

#3 Andreas Jonsson   Moderators   -  Reputation: 3291

Like
0Likes
Like

Posted 20 October 2012 - 08:09 PM

You're confusing the concepts :)

The asIScriptGeneric is used for the generic calling convention, which is for when native calling conventions are not supported

The variable type, ?&, is used to pass any argument type to a function, and yes they can be used with object methods too.

In your case the object method should be implemented like this:

void JGizmo::KeepInBounds( void *ptr. int typeId )
{
   // Determine the type of the argument with the typeId, and then cast the ptr accordingly with reinterpret_cast.
}

// Register it as
engine->RegisterObjectMethod("JGizmo", "void KeepInBounds(?&in)", asMETHOD(JGizmo, KeepInBounds), asCALL_THISCALL);

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

#4 thd.MM   Members   -  Reputation: 208

Like
0Likes
Like

Posted 22 October 2012 - 02:55 AM

Thanks Andreas I suspected that worked. But I want to specifically use asIScriptGeneric* because this function will have variable number of parameters:
void KeepInBounds(?&in)
void KeepInBounds(?&in, ?&in)
void KeepInBounds(?&in, ?&in, ?&in)
etc.

#5 Andreas Jonsson   Moderators   -  Reputation: 3291

Like
1Likes
Like

Posted 22 October 2012 - 07:20 AM

Then the function must be implemented like this:

// Global function, or static class method
void MyGenericFunction(asIScriptGeneric *gen)
{
  for( asUINT n = 0; n < gen->getArgCount(); n++ )
  {
    int type = gen->GetArgTypeId(n);
    void *ptr = gen->GetAddressOfArg(n);

    ... reinterpret_cast the pointer according to its type
  }
}

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

#6 thd.MM   Members   -  Reputation: 208

Like
0Likes
Like

Posted 02 November 2012 - 07:13 AM

Thanks this helped.
Still I would find it super useful to have generic parameters in objects like:

void CObject::MyGenericFunction(asIScriptGeneric *gen)

why can't that work? Any chance of it happening?

#7 SiCrane   Moderators   -  Reputation: 9541

Like
1Likes
Like

Posted 02 November 2012 - 07:29 AM

You can just register a proxy function if you want that behavior. Something like:
void generic_proxy(asIScriptGeneric * gen) {
  CObject * self = static_cast<CObject *>(gen->GetObject());
  self->MyGenericFunction(gen);
}





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS