[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[C ext] default value ???

pere.noel

9/3/2006 11:02:00 AM

i'm writting a C ext to Ruby.
i want the User from ruby being able to pass 1 or 2 arg(s) to this ruby,
without any Ruby wraper.

i know that in standard C their is no way to have a function with
default value.

since i'm not really writting "standard C" rather than a C ext to Rubt,
is their a workaround for that ?

for example :
rb_define_method(cRAliasRecord, "my_function", m_my_function_1_arg,
1);
rb_define_method(cRAliasRecord, "my_function", m_my_function_2_args,
2);

or something similar...
--
une bévue
4 Answers

Robin Stocker

9/3/2006 12:29:00 PM

0

Une bévue wrote:
> i'm writting a C ext to Ruby.
> i want the User from ruby being able to pass 1 or 2 arg(s) to this ruby,
> without any Ruby wraper.
>
> i know that in standard C their is no way to have a function with
> default value.
>
> since i'm not really writting "standard C" rather than a C ext to Rubt,
> is their a workaround for that ?
>
> for example :
> rb_define_method(cRAliasRecord, "my_function", m_my_function_1_arg,
> 1);
> rb_define_method(cRAliasRecord, "my_function", m_my_function_2_args,
> 2);
>
> or something similar...

This question came up just recently:

http://www.google.com/search?q=site%3Ablade.nagaokaut.ac.jp+extension+defaul...

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...

--
Robin

Nobuyoshi Nakada

9/3/2006 12:31:00 PM

0

Hi,

At Sun, 3 Sep 2006 20:05:39 +0900,
Une bévue wrote in [ruby-talk:212421]:
> since i'm not really writting "standard C" rather than a C ext to Rubt,
> is their a workaround for that ?

Define the method as -1 arity, and use rb_scan_args().
There are a lot of examples in the source.

--
Nobu Nakada

pere.noel

9/3/2006 1:15:00 PM

0

<nobu@ruby-lang.org> wrote:

>
> Define the method as -1 arity, and use rb_scan_args().
> There are a lot of examples in the source.

thanks a lot !
--
une bévue

pere.noel

9/3/2006 1:15:00 PM

0

Robin Stocker <robin@nibor.org> wrote:

> This question came up just recently:
>
> [...]


thanks a lot !
--
une bévue