From: William Djaja Tjokroaminata Date: 2002-09-06T00:27:57+09:00 Subject: Re: Is It Possible to Create Block from within C? Hi, Using "rb_iterate()", it works! Now, my code looks like nextState = nil trans.each_key do |key| if trans[key] == true if nextState.nil? then nextState = key else raise_exc ("multiple transitions defined") end end end if nextState.nil? .... There are several problems here. First, inside the block I need to get the value of both "trans" and "nextState". No big deal, I just pack them into a rb_ary in the last argument of rb_iterate(). Second, I need to get the value of "nextState" after rb_iterate() finishes. Probably I can wrap the pointer of nextState in a BigNum, but it will look too ugly. The "best" solution so far is to do array manipulation to get the value of nextState back. Is there an easier or standard way of accessing the "logically enclosing local" variable in a "logical Ruby block" in C, such as for the "nextState" variable in the code above? Regards, Bill ============================================================================= nobu.nokada@softhome.net wrote: > To call a method with block: > static VALUE > statements(VALUE arg, VALUE val) > { > return block_result; > } > static VALUE > call_func(VALUE obj) > { > return rb_funcall(obj, rb_intern("func"), 0); > } > rb_iterate(call_func, obj, statement, 0);