static VALUE gbp_send(VALUE self, VALUE bytes) { gbp_com *gbp; int i; short int status; VALUE ary; Check_Type(bytes, T_ARRAY); Data_Get_Struct(self, gbp_com, gbp); for (i = 0; i < RARRAY_LEN(bytes); i++) { gbp->ibuf[i] = (unsigned char) FIX2INT(RARRAY_PTR(bytes)[i]); } gbp->ibuf_len = RARRAY_LEN(bytes); status = TL_SendReceive(gbp->ibuf_len, gbp->ibuf, &gbp->obuf_len, gbp->obuf); if (status != NO_ERR) { rb_raise(rb_eRuntimeError, get_err_msg(status)); } ary = rb_ary_new2(gbp->obuf_len); for (i = 0; i < gbp->obuf_len; i++) { rb_ary_push(ary, CHR2FIX(gbp->obuf[i])); } return ary; }
static VALUE r_sem_get_char(VALUE self) { static char c; c = *shm; return CHR2FIX(c); }
static VALUE r_sem_put_char(VALUE self, VALUE data) { static char c; c = NUM2CHR(data); *shm = c; return CHR2FIX(c); }
VALUE string_spec_RSTRING_PTR_iterate(VALUE self, VALUE str) { int i; char* ptr; ptr = RSTRING_PTR(str); for(i = 0; i < RSTRING_LEN(str); i++) { rb_yield(CHR2FIX(ptr[i])); } return Qnil; }
static VALUE image_mhash_for(VALUE self, VALUE _filename) { char * filename = StringValuePtr(_filename); uint8_t *hash; int len; if (NULL == (hash = ph_mh_imagehash(filename, len))) { rb_raise(rb_eRuntimeError, "Unknown pHash error"); } VALUE array = rb_ary_new2(72); for (int i=0; i<72; i++) rb_ary_push(array, CHR2FIX(hash[i])); return array; }
/* * call-seq: * codes -> array(contain fixnum) * * Return Freeman chain codes. */ VALUE rb_codes(VALUE self) { CvChain *chain = CVCHAIN(self); CvChainPtReader reader; int total = chain->total; VALUE ary = rb_ary_new2(total); try { cvStartReadChainPoints(chain, &reader); for (int i = 0; i < total; ++i) { CV_READ_SEQ_ELEM(reader.code, (*((CvSeqReader*)&(reader)))); rb_ary_store(ary, i, CHR2FIX(reader.code)); } } catch (cv::Exception& e) { raise_cverror(e); } return ary; }
static VALUE rg_set_markup(int argc, VALUE *argv, VALUE self) { VALUE markup, accel_marker; gunichar accel_char = 0; rb_scan_args(argc, argv, "11", &markup, &accel_marker); StringValue(markup); if (NIL_P(accel_marker)){ pango_layout_set_markup(_SELF(self), RSTRING_PTR(markup), RSTRING_LEN(markup)); } else { pango_layout_set_markup_with_accel(_SELF(self), RSTRING_PTR(markup), RSTRING_LEN(markup), NUM2CHR(accel_marker), &accel_char); } return CHR2FIX(accel_char); }
VALUE rbgobj_gvalue_to_rvalue(const GValue* value) { GType type, fundamental_type; VALUE rvalue; if (!value) return Qnil; type = G_VALUE_TYPE(value); if (rbgobj_convert_gvalue2rvalue(type, value, &rvalue)) return rvalue; fundamental_type = G_TYPE_FUNDAMENTAL(type); switch (fundamental_type) { case G_TYPE_NONE: return Qnil; case G_TYPE_CHAR: return CHR2FIX(g_value_get_char(value)); case G_TYPE_UCHAR: return INT2FIX(g_value_get_uchar(value)); case G_TYPE_BOOLEAN: return CBOOL2RVAL(g_value_get_boolean(value)); case G_TYPE_INT: return INT2NUM(g_value_get_int(value)); case G_TYPE_UINT: return UINT2NUM(g_value_get_uint(value)); case G_TYPE_LONG: return LONG2NUM(g_value_get_long(value)); case G_TYPE_ULONG: return ULONG2NUM(g_value_get_ulong(value)); case G_TYPE_INT64: return rbglib_int64_to_num(g_value_get_int64(value)); case G_TYPE_UINT64: return rbglib_uint64_to_num(g_value_get_uint64(value)); case G_TYPE_FLOAT: return rb_float_new(g_value_get_float(value)); case G_TYPE_DOUBLE: return rb_float_new(g_value_get_double(value)); case G_TYPE_STRING: return CSTR2RVAL(g_value_get_string(value)); case G_TYPE_ENUM: return rbgobj_make_enum(g_value_get_enum(value), type); case G_TYPE_FLAGS: return rbgobj_make_flags(g_value_get_flags(value), type); case G_TYPE_OBJECT: case G_TYPE_INTERFACE: { GObject* gobj = g_value_get_object(value); return gobj ? GOBJ2RVAL(gobj) : Qnil; } case G_TYPE_PARAM: { GParamSpec* pspec = g_value_get_param(value); return pspec ? rbgobj_ruby_object_from_instance(pspec) : Qnil; } case G_TYPE_POINTER: { gpointer ptr = g_value_get_pointer(value); if (!ptr) return Qnil; else return rbgobj_ptr_new(type, ptr); } case G_TYPE_BOXED: { GType gtype; for (gtype = type; gtype != G_TYPE_INVALID; gtype = g_type_parent(gtype)) { GValueToRValueFunc func = g_type_get_qdata(gtype, qGValueToRValueFunc); if (!func) continue; return func(value); } } default: if (!rbgobj_convert_gvalue2rvalue(fundamental_type, value, &rvalue)) { GValueToRValueFunc func; func = g_type_get_qdata(type, qGValueToRValueFunc); if (!func) { g_warning("rbgobj_gvalue_to_rvalue: unsupported type: %s\n", g_type_name(type)); } else { rvalue = func(value); } } return rvalue; } }