From: ts Date: 2001-10-22T22:23:18+09:00 Subject: [ruby-talk:22958] Re: rb_iterate help needed... >>>>> "M" == Mikkel Bruun writes: M> So, the .handle method should go instead of method, the symbol and the M> string should be contained in args. M> *block should be puts. This is just an example, it's stupid but it's normal :-) pigeon% cat tt.c #include extern VALUE rb_defout; static VALUE tt_cDispatch; static VALUE tt_iter(tmp) VALUE *tmp; { return rb_funcall2(tmp[0], rb_intern("handle"), 2, tmp + 1); } static VALUE tt_yield(element) VALUE element; { return rb_funcall2(rb_defout, rb_intern("puts"), 1, &element); } static VALUE tt_foo(obj, xml) VALUE obj, xml; { VALUE tmp[3]; xml = rb_str_to_str(xml); tmp[0] = rb_funcall2(tt_cDispatch, rb_intern("new"), 1, &xml); tmp[1] = ID2SYM(rb_intern("start_element")); tmp[2] = rb_ary_new3(1, rb_str_new2("chapter")); rb_iterate(tt_iter, (VALUE)tmp, tt_yield, 0); return rb_funcall2(tmp[0], rb_intern("start"), 0, 0); } void Init_tt() { VALUE tt_cTt; rb_require("nqxml/dispatcher"); tt_cDispatch = rb_const_get(rb_const_get(rb_cObject, rb_intern("NQXML")), rb_intern("Dispatcher")); tt_cTt = rb_define_class("Tt", rb_cObject); rb_define_singleton_method(tt_cTt, "foo", tt_foo, 1); } pigeon% pigeon% cat b.rb #!/usr/bin/ruby require 'tt' xml = ' My Book

This is the intro to my book,which hasbold ideas

This is the first chapter. It has bold text

Should match chapter/*
a chapter in the appendix
Should match chapter/*

Should match chapter/*

' Tt::foo(xml) pigeon% pigeon% b.rb pigeon% Guy Decoux