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