Advertisement

RegisterGlobalFunction - calling convention?

Started by April 20, 2007 02:15 AM
17 comments, last by russian 17 years, 7 months ago
Global functions can't be thiscall. Declare the method as static in c++ and use either cdecl or generic (with a wrapper).

In you case though, you probably get an error because you're using non-generic calling conventions on an unsupported platform. Which OS/processor are you using?
XP-x86/Athlon64

The method is necessary to me not static.
Advertisement
The class is created as singleton.
I simply do not wish to create in AngelScript object, and to address directly to methods of the single copy of a class.
In scripts at me the index (in the form of int) is simply transferred. Certainly it is not safe, but speed of performance above (imho). And is easier to me so.

Whether so it is possible to get out somehow in the given situation?
If your class is a singleton it has some method to return the instance right? So you could do something like this:

int myWrapper(int tmp){    return MyClass::getInstance().Do(tmp);}


and register the wrapper with angel script. You could even make the wrapper a static method of the singleton class. You might incur an extra function call, but that's really not significant most of the time.

Could something like that work for you?

~Andy
Quote: You could even make the wrapper a static method of the singleton class.

Do you have an example of the code to expose this fn to AS?
I have come to such variant:

.hclass CMy{    static CMy* self;    void Start();    void Do1();    static void Do2(AnyClass* a);    CMy():{self=this;};    ~CMy():{self=NULL;};}.cppCMy* CMy::self=NULL;void CMy::Start(){........    ss->RegisterGlobalFunction("void DoIt(int any)", asFUNCTION(CMy::Do2), asCALL_CDECL);........    AnyClass* a=new AnyClass;    ctx->SetArgDWord(0,(DWORD)(a));........}void CMy::Do1(){}void CMy::Do2(AnyClass* a){    a->x=100;    self->Do1();}AS:void main(int any){    DoIt(any);}


What tell?
Advertisement
_Sigma: it's pretty simple:

engine->RegisterGloabalFunction("int Do(int)", asFUNCTION(MyClass::myWrapper), asCALL_CDECL);

Since static methods are treated the same as global function in c++ you register it like any normal function, just prefixing it with the class name and scope resolution operator.

russian: saw your post while I was writhing this, I'll look it over and get back to you in a sec..

~Andy
Russian, I'm not exactly sure what your code is supposed to do, but it looks like you are registering the static function with angel script properly (assuming conversion between angelscript int and AnyClass* is ok, I'm not sure on that). Is it working as you wanted it to?

~Andy
Yes, it works as it is necessary to me. Censures are not present, reduction of types works well (int <=> pointer *).

I apologize, if something has not answered or has answered incorrectly - I use the electronic translator.

This topic is closed to new replies.

Advertisement