Advertisement

Method overloading in Angelscript

Started by April 24, 2004 06:30 PM
4 comments, last by Desdemona 20 years, 6 months ago
I noticed the other day Angelscript supports method/function overloading now. I have this working with two methods in my C++ code SetView and SetView2 both exposed as SetView in Angelscript. Is there any way to expose overloaded methods to Angelscript (e.g. if both methods in C++ were called SetView)? If I try this using asMETHOD(CCamera::SetView) for both methods then my compiler doesnt know which method I mean. Is there any syntax to tell the compiler which method I mean? Thanks Joe
You'll have to let the compiler know which method you mean by casting the pointer to the right type.

class CTest{  void SetView(int);  void SetView(float);} engine->RegisterObjectMethod("test", "void SetView(int)", asMETHOD((void CTest::(*)(int))SetView), asCALL_THISCALL);engine->RegisterObjectMethod("test", "void SetView(float)", asMETHOD((void CTest::(*)(float))SetView), asCALL_THISCALL);  


Andreas


__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game



[edited by - WitchLord on April 25, 2004 5:57:32 AM]

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
Okay that is pointing me in the right dirrection; I was only familiar with the syntax for function pointers, not methods. But it still doesnt work.

I'm using Visual Studio.NET 2003, and the C++ compiler is coughing up an error with that syntax:

asMETHOD((bool CCamera::(*)(float, float, float))SetView)
error C2589: '(' : illegal token on right side of '::'

Any suggestions? What compiler are you using?

Joe


[edited by - Desdemona on April 25, 2004 6:59:59 AM]
Sorry about that.

I think the correct syntax is without the paranthesis:

asMETHOD((bool CCamera::*(float, float, float))SetView) 


__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Ok, that didnt work either, but it got me started; the correct syntax appears to be

engine->RegisterObjectMethod("CCamera", "void SetView(const VECTOR3& vPosition)", asMETHOD((void (CCamera::*)(const D3DXVECTOR3&))SetView), asCALL_THISCALL);engine->RegisterObjectMethod("CCamera", "void SetView(float x, float y, float z)", asMETHOD((void (CCamera::*)(float, float, float))SetView), asCALL_THISCALL);  


Thanks

[edited by - Desdemona on April 26, 2004 12:22:56 PM]
Just as a reference for anyone else having this problem, using MSVC6 you need to use the following syntax:
asMETHOD((void (CCamera::*)(float, float, float))CCamera::SetView)

Note the extra CCamera towards the end.

- Xavier

This topic is closed to new replies.

Advertisement