Registering Operators
I have a bunch of questions here that i'll clump into one post. I appreciate any useful response I get. :D I recently changed physics engines to physX, and thus had to change math libraries and ran into something I didn't have to worry about before when I bound the math classes. Here are some problems I have: Overloaded constructors, How do I bind these? NX_INLINE NxVec3(); explicit NX_INLINE NxVec3(NxReal a); NX_INLINE NxVec3(NxReal nx, NxReal ny, NxReal nz); NX_INLINE NxVec3(const NxVec3& v); Operators in your SDK vector example use friend Vector3 operator+(const Vector3 &a, const Vector3 &b); but this vector class uses NxVec3 operator +(const NxVec3 & v) const; Aside from modifying the NxVec3 class myself (I dont want to make changes to it), How can I bind this? EDIT: Globally defining NxVec3 operator-(const NxVec3& A,const NxVec3& B) return A.operator -(B); seems like an ugly but workable solution. I have several functions that simply will not bind. I have studied some and simply cannot see the error if there is infact one. Here are some examples: g_ascript_engine->RegisterObjectMethod("NxMat33", "void getRow(int,NxVec3 &out) const", asMETHODPR(NxMat33, getRow,(int,NxVec3&),void), asCALL_THISCALL); Declared as "NX_INLINE void NxMat33::getRow(int row, NxVec3 &) const;" g_ascript_engine->RegisterObjectMethod("NxMat33", "void getColumn(int,NxVec3 &out) const", asMETHODPR(NxMat33, getColumn,(int,NxVec3&),void), asCALL_THISCALL); Declared as "NX_INLINE void NxMat33::getColumn(int col, NxVec3 &) const;" g_ascript_engine->RegisterObjectMethod("NxMat33", "NxVec3 getRow(int) const", asMETHODPR(NxMat33, getRow,(int),NxVec3), asCALL_THISCALL); Declared as "NX_INLINE NxVec3 NxMat33::getRow(int row) const;" g_ascript_engine->RegisterObjectMethod("NxMat33", "NxVec3 getColumn(int) const", asMETHODPR(NxMat33, getColumn,(int),NxVec3), asCALL_THISCALL); Declared as "NX_INLINE NxVec3 NxMat33::getColumn(int col) const;" I get compiler error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'NxVec3 (__thiscall NxMat33::* )(int)' None of the functions with this name in scope match the target type Also, Does Ascript support inline functions? What kind of optimizations does the script compiler support? Thanks for reading, Keep up the great work Andreas. [Edited by - IndependentHat on April 3, 2009 12:56:33 AM]
Currently AngelScript doesn't support registering overloaded dual operators as member methods. You have to write a wrapper for these:
I'm currently working on implementing support for overloadable operators for script declared classes. This will also allow application registered classes to register the overloaded operators as member methods. This ought to be available in version 2.16.1 or 2.16.2.
As for the functions you can't bind, you need to add the keyword 'const' after the parameter list. Example:
C++ inline functions are supported just as any other function. What happens is that when you take the address of the inline function in C++, the C++ compiler gives the address of a non-inline version of the function. So the function you register with AngelScript isn't really inline.
The script compiler performs a bit of bytecode optimizations, e.g. removal of redundant code, and swapping instructions sequences for more efficient instructions. Inlining script functions are not yet implemented, but is something that plan on doing at one time. Eventually I'd also like to add support for JIT compilation.
Regards,
Andreas
NxVec3 NxVec3_subtract(const NxVec3& A,const NxVec3& B){ return A - B;}
I'm currently working on implementing support for overloadable operators for script declared classes. This will also allow application registered classes to register the overloaded operators as member methods. This ought to be available in version 2.16.1 or 2.16.2.
As for the functions you can't bind, you need to add the keyword 'const' after the parameter list. Example:
g_ascript_engine->RegisterObjectMethod( "NxMat33", "void getRow(int,NxVec3 &out) const", asMETHODPR(NxMat33, getRow,(int,NxVec3&) const,void), asCALL_THISCALL);
C++ inline functions are supported just as any other function. What happens is that when you take the address of the inline function in C++, the C++ compiler gives the address of a non-inline version of the function. So the function you register with AngelScript isn't really inline.
The script compiler performs a bit of bytecode optimizations, e.g. removal of redundant code, and swapping instructions sequences for more efficient instructions. Inlining script functions are not yet implemented, but is something that plan on doing at one time. Eventually I'd also like to add support for JIT compilation.
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
Thanks for the fast response, the const change fixed majority of my problems.
Is there any way around writing wrappers for constructors aswell?
Another question, why is there no asIScriptEngine::DiscardModule(asIScriptModule* module) function? I receive a pointer when I create a module, but cannot release it without having to form the module name string : (.
Lastly, and somewhat personal, Im interested as to what your drive to work on this is? You dont appear to be trying to make money but you have spent considerable time into this and continue to give full support to people who use it. Its quite refreshing! :D
Is there any way around writing wrappers for constructors aswell?
Another question, why is there no asIScriptEngine::DiscardModule(asIScriptModule* module) function? I receive a pointer when I create a module, but cannot release it without having to form the module name string : (.
Lastly, and somewhat personal, Im interested as to what your drive to work on this is? You dont appear to be trying to make money but you have spent considerable time into this and continue to give full support to people who use it. Its quite refreshing! :D
Unfortunately there is no way around writing wrappers for constructors. C++ doesn't allow taking the address of a constructor, so there is no way of registering it directly.
There will be a DiscardModule(asIScriptModule *). Earlier versions didn't have the asIScriptModule interface and just I haven't modified all the methods to use the new interface pointer instead of the name. Maybe I'll be able to do it for 2.17.0.
I really wish I could make money from AngelScript, it would have allowed me to dedicate even more time for it. But I have a feeling that if I charged for it in anyway there just wouldn't be anyone using it. Donations are appreciated though.
My drive is probably the great feedback I get from the users on the library. I also get in touch with a lot of professional game developers through AngelScript (and my other projects at AngelCode.com). Something that I hardly would have done otherwise.
There will be a DiscardModule(asIScriptModule *). Earlier versions didn't have the asIScriptModule interface and just I haven't modified all the methods to use the new interface pointer instead of the name. Maybe I'll be able to do it for 2.17.0.
I really wish I could make money from AngelScript, it would have allowed me to dedicate even more time for it. But I have a feeling that if I charged for it in anyway there just wouldn't be anyone using it. Donations are appreciated though.
My drive is probably the great feedback I get from the users on the library. I also get in touch with a lot of professional game developers through AngelScript (and my other projects at AngelCode.com). Something that I hardly would have done otherwise.
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 topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement