Sign in to follow this  
saejox

Register functions with default value parameters

Recommended Posts

Hi,

I want to register this function,

[CODE]
virtual void Ogre::ManualObject::begin ( const String & materialName,
RenderOperation::OperationType opType = RenderOperation::OT_TRIANGLE_LIST,
const String & groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME
)
[/CODE]

i register it so;
[CODE]r = engine->RegisterObjectMethod("ManualObject", "void begin(const string &in, int renderop)", asMETHOD(ManualObject, begin), asCALL_THISCALL);
assert( r >= 0);
[/CODE]

call it with
[CODE]
manual.begin("lootray", OT_LINE_STRIP);
[/CODE]
causes this assertion:
Run-Time Check Failure #2 - Stack around the variable 'retQW' was corrupted

this function works, if i register the whole thing [CODE]void begin(const string &in, int renderop, const string &in)[/CODE]
i think i do the registeration wrong.

How do i register functions with default parameters?

Thanks.

Share this post


Link to post
Share on other sites
Default parameters are entirely a compiler thing-- they're just instructions to the compiler to add some behind-the-scenes code if you don't manually specify arguments when the function is called. Due to how Angelscript works, you can't take advantage of this since it doesn't call functions the 'normal' way. You'll need to actually add the default arguments to the AS declaration instead of just assuming the compiler will handle it.

EDIT: For clarity, I refer specifically to the "void begin(const string &in, int renderop, const string &in)" bit. Edited by InvalidPointer

Share this post


Link to post
Share on other sites
[quote name='InvalidPointer' timestamp='1343256430' post='4963095']
Default parameters are entirely a compiler thing-- they're just instructions to the compiler to add some behind-the-scenes code if you don't manually specify arguments when the function is called. Due to how Angelscript works, you can't take advantage of this since it doesn't call functions the 'normal' way. You'll need to actually add the default arguments to the AS declaration instead of just assuming the compiler will handle it.

EDIT: For clarity, I refer specifically to the "void begin(const string &in, int renderop, const string &in)" bit.
[/quote]

i didnt know angelscript supports default values in declearations.
another awesome feature i missed.

[CODE]
r = engine->RegisterObjectMethod("ManualObject", ("void begin(const string &in, int renderop = 4, const string &in group= \"" + ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME + "\")").c_str(), asMETHOD(ManualObject, begin), asCALL_THISCALL);
[/CODE]

thank you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this