Lambda arguments in an extension

In an extension, how do I differentiate between:

lambda().call()

and:

lambda().call(nil)

Here’s some sample code that demonstrates the problem:

[[email protected] tmp]$ cat test.rb
require ‘test.so’

foo()

[[email protected] 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);
}

[[email protected] tmp]$ cat extconf.rb
require ‘mkmf’
create_makefile(‘test’)
[[email protected] tmp]$ ruby test.rb
nil
nil
42

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs