lambda arguments in an extension

P

Paul Brannan

In an extension, how do I differentiate between:

lambda().call()

and:

lambda().call(nil)

Here's some sample code that demonstrates the problem:

[pbrannan@zaphod tmp]$ cat test.rb
require 'test.so'

foo()

[pbrannan@zaphod tmp]$ cat test.c
#include "ruby.h"

VALUE iter(VALUE obj)
{
VALUE l = rb_funcall(rb_cObject, rb_intern("lambda"), 0);
rb_funcall(l, rb_intern("call"), 0);
rb_funcall(l, rb_intern("call"), 1, Qnil);
rb_funcall(l, rb_intern("call"), 1, INT2NUM(42));
}

VALUE body(VALUE obj, VALUE data)
{
rb_p(obj);
return Qnil;
}

static VALUE foo(VALUE self)
{
rb_iterate(RUBY_METHOD_FUNC(iter), Qnil, RUBY_METHOD_FUNC(body), Qnil);
}

void Init_test()
{
rb_define_method(rb_cObject, "foo", foo, 0);
}

[pbrannan@zaphod tmp]$ cat extconf.rb
require 'mkmf'
create_makefile('test')
[pbrannan@zaphod tmp]$ ruby test.rb
nil
nil
42
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top