• Advertisement

Archived

This topic is now archived and is closed to further replies.

Method overloading in Angelscript

This topic is 5014 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

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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

  • Advertisement