librelist archives

« back to archive

variadic methods in rice

variadic methods in rice

From:
Paul Brannan
Date:
2009-12-31 @ 20:28
So it seems the predecessor to rice (excruby) used to support variadic
methods (methods that take a variable number of arguments):

  inline void rb_cpp_define_method(
    VALUE klass,
    char const * name,
    VALUE(*f)(int, VALUE*, VALUE))
  {
    rb_define_method(klass, name, RUBY_METHOD_FUNC(f), -1);
  }

but it looks like this got removed when Rice was written.

I was thinking it could be supported by requiring that variadic
functions have this signature:

  Ret_T func(Arg0_T self, Rice::Argument_List args)

Doesn't help me right now, since I think this project is bound to rice
1.3, but might be useful in the future.  Any thoughts?

Paul

Re: [rice] variadic methods in rice

From:
Paul Brannan
Date:
2009-12-31 @ 20:38
On Thu, Dec 31, 2009 at 03:28:40PM -0500, Paul Brannan wrote:
> I was thinking it could be supported by requiring that variadic
> functions have this signature:
> 
>   Ret_T func(Arg0_T self, Rice::Argument_List args)
> 
> Doesn't help me right now, since I think this project is bound to rice
> 1.3, but might be useful in the future.  Any thoughts?

I should also mention, the Argument_List class should have a scan_args
member function that wraps rb_scan_args.

Paul

Re: [rice] variadic methods in rice

From:
Jason Roelofs
Date:
2009-12-31 @ 21:30
On Thu, Dec 31, 2009 at 3:38 PM, Paul Brannan <pbrannan@atdesk.com> wrote:

> On Thu, Dec 31, 2009 at 03:28:40PM -0500, Paul Brannan wrote:
> > I was thinking it could be supported by requiring that variadic
> > functions have this signature:
> >
> >   Ret_T func(Arg0_T self, Rice::Argument_List args)
> >
> > Doesn't help me right now, since I think this project is bound to rice
> > 1.3, but might be useful in the future.  Any thoughts?
>
> I should also mention, the Argument_List class should have a scan_args
> member function that wraps rb_scan_args.
>
> Paul
>
>
So not something that Rice would be able to pick up and figure out
automatically via define_method?
( ya what is the template type for func(int var, ...)? )

I can see such a feature definitely being useful, I hadn't thought about it
as I hadn't run into it yet. I'm wondering if
Auto_{,Member}_Function_Wrapper needs more abstraction, especially with the
talk of return policies and the like, those classes are getting really big,
and I'm not sure how we'd fit this feature into the existing dispatching.

What project is this you are working on?

Jason

Re: [rice] variadic methods in rice

From:
Paul Brannan
Date:
2010-01-04 @ 14:41
On Thu, Dec 31, 2009 at 04:30:14PM -0500, Jason Roelofs wrote:
> So not something that Rice would be able to pick up and figure out
> automatically via define_method? 
> ( ya what is the template type for func(int var, ...)? )
> 
> I can see such a feature definitely being useful, I hadn't thought about it as
> I hadn't run into it yet. I'm wondering if Auto_{,Member}_Function_Wrapper
> needs more abstraction, especially with the talk of return policies and the
> like, those classes are getting really big, and I'm not sure how we'd fit this
> feature into the existing dispatching.

If we had an Auto_Functor_Wrapper, then we could turn member functions
into functors and have only one wrapper class (function pointers already
act as functors).

> What project is this you are working on?

Something for work.

Paul