# one more calling convention

This topic is 4614 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi ! The manual says : ----------------------------------------------------------------------- asCALL_CDECL_OBJLAST The function is a normal CDecl function that takes a pointer or reference to an object as the last parameter. Using this calling convention applications can register global functions as object methods. ----------------------------------------------------------------------- And how about one more calling convention? Something like asCALL_THISCALL_BINDED or anything else. This mean next - using this calling convention applications can register object methods as global functions. e.g. I can call RegisterGlobalFunction like this : class Foo { public : void Bar(void) {} } ... Foo fooObj; asIScriptEngine * pEngine; ... pEngine->RegisterGlobalFunction("void FooBar()", asBIND_METHOD(Foo::Bar, (void), void, &fooObj), asCALL_THISCALL_BINDED); and than in script I can simply write : void main() { FooBar(); } and fooObj.Bar() will be called. So, I don't need to register class Foo with constructor/destructor/etc. Also, and this is more important for me, the script writer knows nothing about class Foo and its methods. I can solve this problem by using the singleton pattern or global instance of Foo, but this doesn't look good to me. Is it possible to have similar functionality in AngelScript ? Regards, Andrey.

##### Share on other sites
This is certainly possible. In fact, I don't think it would be too difficult to implement. However, I wonder if it is really worth it, and I need to consider the possible impact to the rest of the library.

From the script writer's point of view you can already do this, by writing and registering global functions that would then call the object's methods. I know you said that you don't like that, but I think it can be made quite good.

#include "foo.h"#include "angelscript.h"Foo *fooInstance = 0;void Foo_Bar(){  fooInstance->Bar();}void RegisterFooFunctions(asIScriptEngine *engine, Foo *fooObj){  assert( fooInstance == 0 || fooInstance == fooObj );  fooInstance = fooObj;  int r;  r = engine->RegisterGlobalFunction("void FooBar()", asFUNCTION(Foo_Bar), asCALL_CDECL); assert( r >= 0 );}

I'll think about this, and maybe in a future version AngelScript will natively support bound methods like this.

Thanks for the idea.

Regards,
Andreas