static VALUE enumerator_with_object_i(VALUE val, VALUE memo, int argc, VALUE *argv) { if (argc <= 1) return rb_yield_values(2, val, memo); return rb_yield_values(2, rb_ary_new4(argc, argv), memo); }
static VALUE enumerator_with_index_i(VALUE val, VALUE m, int argc, VALUE *argv) { VALUE *memo = (VALUE *)m; VALUE idx = *memo; *memo = rb_int_succ(idx); if (argc <= 1) return rb_yield_values(2, val, idx); return rb_yield_values(2, rb_ary_new4(argc, argv), idx); }
static VALUE enumerator_with_index_i(VALUE val, VALUE *memo, int argc, VALUE *argv) { VALUE idx; idx = INT2FIX(*memo); ++*memo; if (argc <= 1) return rb_yield_values(2, val, idx); return rb_yield_values(2, rb_ary_new4(argc, argv), idx); }
VALUE invoke_Array_each_special_block(VALUE ary) { rb_thread_t *th = GET_THREAD(); rb_block_t *orig_block = GC_GUARDED_PTR_REF(th->cfp->lfp[0]); if (BUILTIN_TYPE(orig_block->iseq) != T_NODE) { VALUE tsiseqval = iseq_special_block(orig_block->iseq, build_Array_each_node); rb_iseq_t *tsiseq; VALUE argv[2]; if (tsiseqval) { VALUE val; rb_block_t block = *orig_block; GetISeqPtr(tsiseqval, tsiseq); block.iseq = tsiseq; th->cfp->lfp[0] = GC_GUARDED_PTR(&block); argv[0] = 0; argv[1] = ary; val = rb_yield_values(2, argv); if (val == Qundef) { return ary; } else { return val; } } } return Qundef; }
VALUE invoke_Range_each_special_block(VALUE range, VALUE beg, VALUE end, int excl) { rb_thread_t *th = GET_THREAD(); rb_block_t *orig_block = GC_GUARDED_PTR_REF(th->cfp->lfp[0]); if (BUILTIN_TYPE(orig_block->iseq) != T_NODE) { void *builder = excl ? build_Range_each_node_LT : build_Range_each_node_LE; VALUE tsiseqval = iseq_special_block(orig_block->iseq, builder); rb_iseq_t *tsiseq; VALUE argv[2]; if (tsiseqval) { VALUE val; rb_block_t block = *orig_block; GetISeqPtr(tsiseqval, tsiseq); block.iseq = tsiseq; th->cfp->lfp[0] = GC_GUARDED_PTR(&block); argv[0] = beg; argv[1] = end; val = rb_yield_values(2, argv); if (val == Qundef) { return range; } else { return val; } } } return Qundef; }
/* :nodoc: */ static void sprite_list_move_inner(VALUE vlist, ID id, VALUE x, VALUE y) { VALUE list = rb_iv_get(vlist, str_list); int i; VALUE *ptr = RARRAY_PTR(list); if(rb_block_given_p() == Qtrue) { for(i=0; i<RARRAY_LEN(list); i++) { VALUE e = *(ptr+i); VALUE ret = rb_yield_values(4, e, INT2NUM(i), x, y); VALUE r1 = rb_funcall(ret, id_kakko, 1, nZero); VALUE r2 = rb_funcall(ret, id_kakko, 1, nOne); rb_funcall(e, id, 2, r1, r2); } } else { for(i=0; i<RARRAY_LEN(list); i++) { VALUE v = *(RSTRUCT_PTR(*(ptr+i))+1); rb_funcall(v, id, 2, x, y); } } }
VALUE invoke_Integer_times_special_block(VALUE num) { rb_thread_t *th = GET_THREAD(); rb_block_t *orig_block = GC_GUARDED_PTR_REF(th->cfp->lfp[0]); if (orig_block && BUILTIN_TYPE(orig_block->iseq) != T_NODE) { VALUE tsiseqval = iseq_special_block(orig_block->iseq, build_Integer_times_node); rb_iseq_t *tsiseq; VALUE argv[2], val; if (tsiseqval) { rb_block_t block = *orig_block; GetISeqPtr(tsiseqval, tsiseq); block.iseq = tsiseq; th->cfp->lfp[0] = GC_GUARDED_PTR(&block); argv[0] = INT2FIX(0); argv[1] = num; val = rb_yield_values(2, argv); if (val == Qundef) { return num; } else { return val; } } } return Qundef; }
static int search(int argc, VALUE* argv, VALUE self) { int lower = 0; int upper = RARRAY_LEN(self) - 1; int i, comp; if(argc == 2){ lower = NUM2INT(argv[0]); upper = NUM2INT(argv[1]); }else if(argc == 3){ lower = NUM2INT(argv[1]); upper = NUM2INT(argv[2]); } while(lower <= upper) { i = lower + (upper - lower) / 2; if(argc == 1 || argc == 3) { comp = NUM2INT(rb_funcall(argv[0], id_cmp, 1, rb_ary_entry(self, i))); } else { comp = NUM2INT(rb_yield_values(1, rb_ary_entry(self, i))); } if(comp == 0) { return i; } else if(comp > 0) { lower = i + 1; } else { upper = i - 1; } } return -1; }
static VALUE enumerator_with_index_i(VALUE val, VALUE *memo) { val = rb_yield_values(2, val, INT2FIX(*memo)); ++*memo; return val; }
/** * call-seq: * instance.each_property do |name, value| * ... * end * * enumerates properties yielding the property name and * its value * */ static VALUE each_property(VALUE self) { CIMCInstance *ptr; CIMCStatus status; int k=0; int num_props=0; CIMCString *property_name = NULL; CIMCData data; Data_Get_Struct(self, CIMCInstance, ptr); num_props = ptr->ft->getPropertyCount(ptr, &status); if (!status.rc) { for (; k < num_props; ++k) { data = ptr->ft->getPropertyAt(ptr, k, &property_name, &status); if (!status.rc) { rb_yield_values(2, (property_name ? rb_str_intern(rb_str_new2(property_name->ft->getCharPtr(property_name, NULL))) : Qnil), sfcc_cimdata_to_value(data)); } else { sfcc_rb_raise_if_error(status, "Can't retrieve property #%d", k); } if (property_name) CMRelease(property_name); } } else { sfcc_rb_raise_if_error(status, "Can't retrieve property count"); } return Qnil; }
static void dict_each_pair (const char *key, xmmsv_t *value, void *udata) { VALUE *parent = udata; rb_yield_values (2, ID2SYM (rb_intern (key)), extract_value (*parent, value)); }
static int cmp_1(const void *ap, const void *bp, void *dummy) { struct sort_data *d = dummy; VALUE a = rb_enc_str_new(ap, d->elsize, d->enc); VALUE b = rb_enc_str_new(bp, d->elsize, d->enc); VALUE retval = rb_yield_values(2, a, b); return rb_cmpint(retval, a, b); }
VALUE perform_scan(VALUE device_id_in) { int device_id = FIX2INT(device_id_in); int device_handle = device_handles[device_id]; unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr; int len; int keep_scanning = 1; while (keep_scanning) { evt_le_meta_event *meta; le_advertising_info *info; int ret; // wait for data with a timeout fd_set set; struct timeval timeout; FD_ZERO(&set); FD_SET(device_handle, &set); timeout.tv_sec = 0; timeout.tv_usec = 200000; // 200ms ret = select(device_handle + 1, &set, NULL, NULL, &timeout); if (ret < 0) { rb_raise(rb_eException, "Error waiting for data"); } else if (ret == 0) { // timeout. yield nil to give ruby a chance to stop the scan. keep_scanning = rb_yield(Qnil) != Qfalse; continue; } // keep trying to read until we get something while ((len = read(device_handle, buf, sizeof(buf))) < 0) { if (errno == EAGAIN || errno == EINTR) { continue; } keep_scanning = 0; break; } if (len > 0) { VALUE rssi, ad_data, addr; ptr = buf + (1 + HCI_EVENT_HDR_SIZE); len -= (1 + HCI_EVENT_HDR_SIZE); meta = (void *) ptr; // check if this event is an advertisement if (meta->subevent != EVT_LE_ADVERTISING_REPORT) { continue; } // parse out the ad data, the mac, and the rssi info = (le_advertising_info *) (meta->data + 1); rssi = INT2FIX( (int8_t)info->data[info->length] ); ad_data = rb_str_new((void *)info->data, info->length); addr = ba2value(&info->bdaddr); keep_scanning = rb_yield_values(3, addr, ad_data, rssi) != Qfalse; } } return Qnil; }
static void attr_each (const char *key, xmmsv_t *value, void *udata) { const char *s; xmmsv_get_string (value, &s); switch (XPOINTER_TO_INT (udata)) { case EACH_PAIR: rb_yield_values (2, rb_str_new2 (key), rb_str_new2 (s)); break; case EACH_KEY: rb_yield_values (1, rb_str_new2 (key)); break; case EACH_VALUE: rb_yield_values (1, rb_str_new2 (s)); break; } }
VALUE _each(VALUE self) { RETURN_ENUMERATOR(self,0,NULL); for(unsigned int i = 0;i<CEGUI::FIC_FRAME_IMAGE_COUNT;++i) { const CEGUI::Image *image = _self->getImage((CEGUI::FrameImageComponent)i); if(image) rb_yield_values(2,wrap((CEGUI::FrameImageComponent)i),wrap(image)); } return self; }
static VALUE pq_pop_each(VALUE self) { fc_pq::PQueue queue= pq_from_self(self); while( !fc_pq::empty(queue) ) { VALUE value = (VALUE) fc_pq::top(queue); double key = fc_pq::top_key(queue); fc_pq::pop(queue); rb_yield_values(2, value, DBL2NUM(key)); } return self; }
static int keep_if_i(VALUE key, VALUE value, VALUE hash) { if (key != Qundef) { const bool ok = RTEST(rb_yield_values(2, key, value)); ST_STOP_IF_BROKEN(); if (!ok) { return ST_DELETE; } } return ST_CONTINUE; }
static int select_i(VALUE key, VALUE value, VALUE result) { if (key != Qundef) { const bool ok = RTEST(rb_yield_values(2, key, value)); ST_STOP_IF_BROKEN(); if (ok) { rb_hash_aset(result, key, value); } } return ST_CONTINUE; }
static int delete_if_i(VALUE key, VALUE value, VALUE ary) { if (key != Qundef) { const bool ok = RTEST(rb_yield_values(2, key, value)); ST_STOP_IF_BROKEN(); if (ok) { rb_ary_push(ary, key); } } return ST_CONTINUE; }
static int update_block_i(VALUE key, VALUE value, VALUE hash) { if (key != Qundef) { if (rhash_has_key(hash, 0, key)) { value = rb_yield_values(3, key, rhash_aref(hash, 0, key), value); ST_STOP_IF_BROKEN(); } rhash_aset(hash, 0, key, value); } return ST_CONTINUE; }
static void state_setup_block(struct State * state) { int i, j; for(i = 0 ; i < state->height ; i++){ for(j = 0 ; j < state->width ; j++){ if (rb_yield_values(2, INT2FIX(i), INT2FIX(j))){ BITON(state->mat, i, j, state->n_bytes); } } } }
static VALUE mTokyoMessenger_each_key(VALUE vself){ VALUE vrv; char *kxstr; if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given"); TCRDB *db = mTokyoMessenger_getdb(vself); vrv = Qnil; tcrdbiterinit(db); while((kxstr = tcrdbiternext2(db)) != NULL){ vrv = rb_yield_values(1, rb_str_new2(kxstr)); } return vrv; }
/* * call-seq: * each_attribute -> Enumerator * each_attribute { |name, value| } -> self * * iterates the attributes in this property. * ===Return value * self * */ DLL_LOCAL VALUE _each_attribute(VALUE self) { RETURN_SIZED_ENUMERATOR(self,0,NULL,RUBY_METHOD_FUNC(_each_attribute_size)); const wxPGAttributeStorage& attrs = _self->GetAttributes(); wxPGAttributeStorage::const_iterator it = attrs.StartIteration(); wxVariant var; while(attrs.GetNext(it,var)) rb_yield_values(2,wrap(var.GetName()),wrap(var)); return self; }
static int env_update_i(VALUE key, VALUE val, VALUE ctx) { if (key != Qundef) { if (rb_block_given_p()) { val = rb_yield_values(3, key, rb_f_getenv(Qnil, 0, key), val); RETURN_IF_BROKEN(); } env_aset(Qnil, 0, key, val); } return ST_CONTINUE; }
static VALUE rb_struct_each_pair(VALUE s) { VALUE members; long i; RETURN_ENUMERATOR(s, 0, 0); members = rb_struct_members(s); for (i=0; i<RSTRUCT_LEN(s); i++) { rb_yield_values(2, rb_ary_entry(members, i), RSTRUCT_PTR(s)[i]); } return s; }
/* * call-seq: * EnumDescriptor.each(&block) * * Iterates over key => value mappings in this enum's definition, yielding to * the block with (key, value) arguments for each one. */ VALUE EnumDescriptor_each(VALUE _self) { DEFINE_SELF(EnumDescriptor, self, _self); upb_enum_iter it; for (upb_enum_begin(&it, self->enumdef); !upb_enum_done(&it); upb_enum_next(&it)) { VALUE key = ID2SYM(rb_intern(upb_enum_iter_name(&it))); VALUE number = INT2NUM(upb_enum_iter_number(&it)); rb_yield_values(2, key, number); } return Qnil; }
/* * call-seq: * set_roi(<i>rect</i>) * set_roi(<i>rect</i>){|image| ...} * * Set ROI. <i>rect</i> should be CvRect or compatible object. * Return self. */ VALUE rb_set_roi(VALUE self, VALUE roi) { VALUE block = rb_block_given_p() ? rb_block_proc() : 0; if (block) { CvRect prev_roi = cvGetImageROI(IPLIMAGE(self)); cvSetImageROI(IPLIMAGE(self), VALUE_TO_CVRECT(roi)); rb_yield_values(1, self); cvSetImageROI(IPLIMAGE(self), prev_roi); } else { cvSetImageROI(IPLIMAGE(self), VALUE_TO_CVRECT(roi)); } return self; }
/* * call-seq: * set_coi(<i>coi</i>) * set_coi(<i>coi</i>){|image| ...} * * Set COI. <i>coi</i> should be Fixnum. * Return self. */ VALUE rb_set_coi(VALUE self, VALUE coi) { VALUE block = rb_block_given_p() ? rb_block_proc() : 0; if (block) { int prev_coi = cvGetImageCOI(IPLIMAGE(self)); cvSetImageCOI(IPLIMAGE(self), FIX2INT(coi)); rb_yield_values(1, self); cvSetImageCOI(IPLIMAGE(self), prev_coi); } else { cvSetImageCOI(IPLIMAGE(self), FIX2INT(coi)); } return self; }
/* :nodoc: */ static VALUE sprite_list_each_index(VALUE self) { int i; VALUE array; RETURN_ENUMERATOR(self, 0, 0); array = rb_iv_get(self, str_list); for(i=0; i<RARRAY_LEN(array); i++) rb_yield_values(1, INT2NUM(i)); return self; }
static int update_func(st_data_t key, st_data_t *value, st_data_t arg) { VALUE ret = rb_yield_values(2, (VALUE)key, (VALUE)*value); switch (ret) { case Qfalse: return ST_STOP; case Qnil: return ST_DELETE; default: *value = ret; return ST_CONTINUE; } }