2009-06-07から1日間の記事一覧

渡されたブロックをProcで取得する

忘れがちなのでメモ。 rb_block_proc();

rb_iterate

忘れがちなのでメモ。 #include "ruby.h" static VALUE main_proc(VALUE arg) { VALUE each = arg; return rb_funcall(each, rb_intern("call"), 0); } static VALUE block(VALUE call_arg, VALUE block_arg, VALUE self) { rb_p(call_arg); rb_p(block_arg)…

win32fiber(失敗)

WindowsのFiberでcoroutineを作れないかと思ったものの、案の定、失敗。 動かないソースだけ貼り付けとく。 #include <windows.h> #include "ruby.h" static VALUE Fiber; static VALUE FiberError; struct win32fiber { LPVOID main_fiber; LPVOID fiber; VALUE proc; </windows.h>…

Queueによるcoroutineもどき

require 'thread' class Coroutine def initialize(&block) raise 'block not given' unless block_given? @q = Queue.new @th = Thread.start do @q.pop block.call(self) end end def yield @q.pop end def resume(*args) @q.push(args) end end coroutine…

インディ大高ジョーンズ

なつかしーwww