Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Register object behavior with pointer to instance function


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
4 replies to this topic

#1 Isaac Paul   Members   -  Reputation: 161

Like
0Likes
Like

Posted 28 February 2013 - 10:49 AM

Is it possible to pass a pointer to an instanced class method (&creationsClass.createScriptObject) when registering an object behavior?

 

I need specific behavior for certain script objects when they're created. I'm trying to avoid using static variables and classes as much as possible which doesn't allow me to simply create a static variable to store the object type for the garbage collector and many other things I need to instantiate a script object.

 

I kind of want to do something like this (but obviously it doesn't work):
 

#define asInstanceMethod(c,m) asSMethodPtr<sizeof(c)>::Convert((&c.m))

void Texture::registerAS(asIScriptEngine* engine, ScriptObjectCreationCache& creationCache) {
    int r;
    static const char* const strComponent = "Texture";
    r = engine->RegisterObjectType(strComponent, sizeof(Texture), asOBJ_REF | asOBJ_GC); assert(r >= 0);
    r = engine->RegisterObjectBehaviour(strComponent, asBEHAVE_FACTORY, "Texture@ f()", asInstanceMethod(creationCache, TSFactory), asCALL_CDECL); assert( r >= 0 );
    r = engine->RegisterObjectBehaviour(strComponent, asBEHAVE_FACTORY, "Texture@ f(const string &in)", asInstanceMethod(creationCache, TSFactoryArg), asCALL_CDECL); assert( r >= 0 );
    
    registerMembers<Texture>(engine, strComponent);
}

 

 

I would greatly appreciate any additional info. 

 

 

edit: I left a pretty crappy post earlier because I had to quickly go somewhere.. I fixed it up now ;)


Edited by izackp, 28 February 2013 - 12:37 PM.


Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3220

Like
0Likes
Like

Posted 28 February 2013 - 01:40 PM

You mean something like this:

 

 
class MySingleton
{
// Class method to be called from script as if a global function
void MyGlobalFunc(int arg1, int arg2);
};
 
MySingleton single;
 
// Registering the singleton's method as if a global function
r = engine->RegisterGlobalFunction("void MyGlobalFunc(int, int)", asMETHOD(MySingleton, MyGlobalFunc), asCALL_THISCALL_ASGLOBAL, &single); assert( r >= 0 );

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 Isaac Paul   Members   -  Reputation: 161

Like
0Likes
Like

Posted 01 March 2013 - 06:11 AM

Sort of... I ended up hacking it in by adding an extra parameter to the registerObjectBehavior function so now I can do this:
 

void SpriteScripted::registerAS(asIScriptEngine* engine, ScriptObjectCreationCache& creationCache) {
    int r;
    static const char* const strComponent = "Sprite";
    r = engine->RegisterObjectType(strComponent, sizeof(SpriteScripted), asOBJ_REF | asOBJ_GC); assert(r >= 0);
    r = engine->RegisterObjectBehaviour(strComponent, asBEHAVE_FACTORY, "Sprite@ f()", asMETHOD(ScriptObjectCreationCache, SSFactory), asCALL_THISCALL_ASGLOBAL, &creationCache); assert( r >= 0 );
    ....
}

 

 

it seems to work but I still have yet to run the angel script unit tests.


Edited by izackp, 01 March 2013 - 06:18 AM.


#4 Andreas Jonsson   Moderators   -  Reputation: 3220

Like
0Likes
Like

Posted 01 March 2013 - 07:56 AM

Yes, that should work. I didn't think about the factory functions when I added the support for asCALL_THISCALL_ASGLOBAL. I'll have this added for 2.27.0.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#5 Andreas Jonsson   Moderators   -  Reputation: 3220

Like
0Likes
Like

Posted 25 May 2013 - 03:21 PM

The support for asCALL_THISCALL_ASGLOBAL in behaviours and also the string factory has been added in revision 1646.

 

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




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