[C ext] default value ???

U

Une bévue

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...
 
R

Robin Stocker

Une said:
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:blade.nagaokaut.ac.jp+extension+default+argument

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/211001
 
N

nobu

Hi,

At Sun, 3 Sep 2006 20:05:39 +0900,
Une b=E9vue 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.

--=20
Nobu Nakada
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,049
Members
48,769
Latest member
Clifft

Latest Threads

Top