Jump to content
  • Advertisement
Sign in to follow this  
_Dreamer

one more calling convention

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!