Register functions with default value parameters

Started by
1 comment, last by saejox 11 years, 8 months ago
Hi,

I want to register this function,


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


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


call it with

manual.begin("lootray", OT_LINE_STRIP);

causes this assertion:
Run-Time Check Failure #2 - Stack around the variable 'retQW' was corrupted

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

How do i register functions with default parameters?

Thanks.
Advertisement
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.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

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.


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


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);


thank you.

This topic is closed to new replies.

Advertisement