本文整理汇总了C++中rb_yield_values函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_yield_values函数的具体用法?C++ rb_yield_values怎么用?C++ rb_yield_values使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_yield_values函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: enumerator_with_index_i
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);
}
示例2: invoke_Array_each_special_block
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;
}
示例3: invoke_Range_each_special_block
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;
}
示例4: sprite_list_move_inner
/*
: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);
}
}
}
示例5: invoke_Integer_times_special_block
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;
}
示例6: search
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;
}
示例7: enumerator_with_index_i
static VALUE
enumerator_with_index_i(VALUE val, VALUE *memo)
{
val = rb_yield_values(2, val, INT2FIX(*memo));
++*memo;
return val;
}
示例8: each_property
/**
* 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;
}
示例9: dict_each_pair
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));
}
示例10: cmp_1
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);
}
示例11: perform_scan
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;
}
示例12: attr_each
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;
}
}
示例13: _each
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;
}
示例14: pq_pop_each
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;
}
示例15: keep_if_i
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;
}