Jump to content
  • Advertisement
Sign in to follow this  
saejox

Register functions with default value parameters

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

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.

Share this post


Link to post
Share on other sites
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. Edited by InvalidPointer

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.


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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!