Example #1
0
/*
  数字类型
  字符串类型
  对象类型
  数组类型(元素为数字,字符串,对象)
 */
QVariant MarshallRuby::VALUE2Variant(VALUE v)
{

    QVariant rv;
    QString str, str2;
    void *ci = NULL;
    QObject *obj = NULL;

    VALUE v1;
    VALUE v2;
    VALUE v3;
    
    switch (TYPE(v)) {
    case T_NONE:  rv = QVariant(); break;
    case T_FIXNUM: rv = (int)FIX2INT(v); break;
    case T_STRING:  rv = RSTRING_PTR(v); break;
    case T_FLOAT:  rv = RFLOAT_VALUE(v); break;
    case T_NIL:   rv = 0; break;
    case T_TRUE:  rv = true; break;
    case T_FALSE: rv = false; break;
    case T_OBJECT:
        str = QString(rb_class2name(RBASIC_CLASS(v)));
        ci = Qom::inst()->getObject(v);
        // obj = dynamic_cast<QObject*>(ci);
        qDebug()<<"unimpl VALUE:"<<str<<ci<<obj;
        // rv = QVariant(QMetaType::VoidStar, ci);
        rv = QVariant::fromValue(ci);
        break;
    case T_ARRAY: {
        QStringList ary;
        // ary << "a123" << "b3456";
        qDebug()<<RARRAY_LEN(v)<<QT_VERSION;
        for (int i = 0; i < RARRAY_LEN(v); i++) {
            ary << VALUE2Variant(rb_ary_entry(v, i)).toString();
        }
        rv = QVariant(ary);
    }; break;
    case T_STRUCT:
        qDebug()<<"use VALUE2Variant2 function.";
        break;
    case T_CLASS:
    default:
        qDebug()<<"unknown VALUE type:"<<TYPE(v);
        break;
    }
    
    return (rv);
}
Example #2
0
// Refer Ruby source ext/objspace/object_tracing.c::newobj_i
static void newobj_i(VALUE tpval, void *data) {
  rbkit_obj_created_event *event;
  rbkit_logger * arg = (rbkit_logger *)data;
  rb_trace_arg_t *tparg = rb_tracearg_from_tracepoint(tpval);
  rbkit_allocation_info *info = new_rbkit_allocation_info(tparg, arg->str_table, arg->object_table);

  VALUE obj = rb_tracearg_object(tparg);
  VALUE klass = RBASIC_CLASS(obj);
  const char *class_name = NULL;
  if (!NIL_P(klass) && BUILTIN_TYPE(obj) != T_NONE && BUILTIN_TYPE(obj) != T_ZOMBIE && BUILTIN_TYPE(obj) != T_ICLASS)
    class_name = rb_class2name(klass);

  event = new_rbkit_obj_created_event(FIX2ULONG(rb_obj_id(obj)), class_name, info);
  pack_event((rbkit_event_header *)event, arg->msgpacker);
  free(event);
  send_message(arg->sbuf);
}
Example #3
0
void
rb_alias(VALUE klass, ID name, ID def)
{
    VALUE target_klass = klass;
    VALUE defined_class;
    rb_method_entry_t *orig_me;
    rb_method_flag_t flag = NOEX_UNDEF;

    if (NIL_P(klass)) {
	rb_raise(rb_eTypeError, "no class to make alias");
    }

    rb_frozen_class_p(klass);

  again:
    orig_me = search_method(klass, def, &defined_class);

    if (UNDEFINED_METHOD_ENTRY_P(orig_me) ||
	UNDEFINED_REFINED_METHOD_P(orig_me->def)) {
	if ((!RB_TYPE_P(klass, T_MODULE)) ||
	    (orig_me = search_method(rb_cObject, def, 0),
	     UNDEFINED_METHOD_ENTRY_P(orig_me))) {
	    rb_print_undef(klass, def, 0);
	}
    }
    if (orig_me->def->type == VM_METHOD_TYPE_ZSUPER) {
	klass = RCLASS_SUPER(klass);
	def = orig_me->def->original_id;
	flag = orig_me->flag;
	goto again;
    }
    if (RB_TYPE_P(defined_class, T_ICLASS)) {
	VALUE real_class = RBASIC_CLASS(defined_class);
	if (real_class && RCLASS_ORIGIN(real_class) == defined_class)
	    defined_class = real_class;
    }

    if (flag == NOEX_UNDEF) flag = orig_me->flag;
    method_entry_set(target_klass, name, orig_me, flag, defined_class);
}
Example #4
0
// Range类型支持
QVector<QVariant> MarshallRuby::VALUE2Variant2(VALUE v)
{
    QVector<QVariant> rvs(1);
    QVariant rv;
    QString str, str2;
    void *ci = NULL;
    QObject *obj = NULL;

    VALUE v1;
    VALUE v2;
    VALUE v3;
    
    switch (TYPE(v)) {
    case T_NONE:  rv = QVariant(); break;
    case T_FIXNUM: rv = (int)FIX2INT(v); break;
    case T_STRING:  rv = RSTRING_PTR(v); break;
    case T_FLOAT:  rv = RFLOAT_VALUE(v); break;
    case T_NIL:   rv = 0; break;
    case T_TRUE:  rv = true; break;
    case T_FALSE: rv = false; break;
    case T_OBJECT:
        str = QString(rb_class2name(RBASIC_CLASS(v)));
        ci = Qom::inst()->getObject(v);
        // obj = dynamic_cast<QObject*>(ci);
        qDebug()<<"unimpl VALUE:"<<str<<ci<<obj;
        // rv = QVariant(QMetaType::VoidStar, ci);
        rv = QVariant::fromValue(ci);
        break;
    case T_ARRAY: {
        QStringList ary;
        // ary << "a123" << "b3456";
        qDebug()<<RARRAY_LEN(v)<<QT_VERSION;
        for (int i = 0; i < RARRAY_LEN(v); i++) {
            // FIXME: 也可能是对象数组,如Qt5::QString,但toString方法不好用。
            // FIXME: 如,[Qt5::QApplication.translate("MainWindow", "acbc", nil), "efgggggg", "hijjjjjjjj"]
            ary << VALUE2Variant(rb_ary_entry(v, i)).toString();
        }
        rv = QVariant(ary);
    }; break;
    case T_STRUCT: {
        str = rb_class2name(RBASIC_CLASS(v));
        if (str == "Range") {
            // qDebug()<<"Range is struct???"<<BUILTIN_TYPE(v)
            //         <<rb_class2name(RBASIC_CLASS(v))
            //         <<RSTRUCT_LEN(v);
            v1 = RSTRUCT_GET(v, 0);
            v2 = RSTRUCT_GET(v, 1);
            v3 = RSTRUCT_GET(v, 2);
            // qDebug()<<TYPE(v1)<<TYPE(v2)<<TYPE(v3);
            // qDebug()<<FIX2INT(v1)<<FIX2INT(v2);

            rv = QVariant(FIX2INT(v1));
            rvs.append(QVariant(FIX2INT(v2)));
        } else {
            qDebug()<<"unsupported struct type:"<<str;
        }
    }; break;
    case T_CLASS:
    default:
        qDebug()<<"unknown VALUE type:"<<TYPE(v);
        break;
    }
    
    rvs[0] = rv;
    return (rvs);
}