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?
RegisterGlobalFunction - calling convention?
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?
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:
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
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:
What tell?
.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?
_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
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
~Andy
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement