one more calling convention
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.
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.
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
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
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 seems like it would still have the same problems as the accepted way. The only thing it does is remove the need for wrapper functions, and that's a pretty lousy reason for adding complexity. You still need to maintain the global object it's binded too - unless AngelScript made its own copy; but then the object couldn't have state. Let us also consider what happens if you want to change which instance is bound. This is trivial with the wrapper solution, but nearly impossible with the new calling convention. You would have to un-bind functions (Something that I do not think is currently possible), re-bind new ones, then re-build every script. Additionally, you would have to write wrappers anyway if you wanted to port your app to a system that only supports the generic calling convention. The wrapper solution is much more robust in every way.
I'm actually planning on going completly AS_CALL_GENERIC. I don't think it's going to be fun. :)
I'm actually planning on going completly AS_CALL_GENERIC. I don't think it's going to be fun. :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement