Jump to content
  • Advertisement
Sign in to follow this  
Silvo

[C++, Ruby] function(...) with no defined arguments

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

G'day! It seems that Ruby wants me to have any function I try to extend to Ruby from C++ to be in the form of: static VALUE function(...); This works fine if I only want to have C++ functions that take no arguments, but I want to take a string from ruby, so I'd need to extract a VALUE from the ...'s. But to my knowledge, va_list and its friends (non OO friends, "friend" as in "mates") need to have a beginning of the whole argument list, so I tried: static function(VALUE val); and static function(VALUE val, ...); But these arn't acceptable. Is there a way I can either trick Ruby into accepting one of these forms, or be able to read from a variable-argument list without a "beginning argument"??

Share this post


Link to post
Share on other sites
Advertisement
OK. Let me rephrase that...

In C++, how do you bind a function for use with ruby?

rb_define_method() should work. I've tried this with functions that take no ruby arguments, which look like the following:

static VALUE function(...);

This works fine, if I change rb_define_method()'s argument for number of arguments for the C++ function from Ruby from 0 to 1 (i.e. it accepts one function from a ruby script) and leave the function looking like so:

static VALUE function(...);

It works. But assume that I actually need to use the argument recived from ruby, how would I go about doing that?? va_list (used to access the arguments passed with "...") needs a starting point for the arguments (i.e. an argument before the "..."), but putting in something like:

static VALUE function(VALUE val, ...);

Gives me this error:

error C2664: 'rb_define_method' : cannot convert parameter 3 from 'VALUE (__cdecl *)(VALUE,...)' to 'VALUE (__cdecl *)(...)'

So, clearly I cannot change the argument list for function() from (...), but this means that va_list does not have a starting point, so it cannot fetch the supplied arguments.

Does that make sense?? Thanks for your help!

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!