示例#1
0
extern "C" VALUE
rb_data_object_alloc(VALUE klass, void* data, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree)
{
    JLocalEnv env;

    RubyData* h = new RubyData;

    TAILQ_INSERT_TAIL(&dataHandles, h, dataList);
    h->toRData()->data = data;
    h->toRData()->dmark = dmark;
    h->toRData()->dfree = dfree;
    h->setType(T_DATA);

    jvalue params[3];
    params[0].l = getRuntime();
    params[1].l = valueToObject(env, klass);
    params[2].j = p2j(h);

    jobject obj = env->CallStaticObjectMethodA(RubyData_class, RubyData_newRubyData_method, params);
    checkExceptions(env);

    h->obj = env->NewGlobalRef(obj);
    checkExceptions(env);


    return (VALUE) (uintptr_t) h;
}
示例#2
0
extern "C" VALUE
rb_float_new(double value)
{
    JLocalEnv env;

    //env->CallStaticObjectMethod();
    RubyFloat* f = new RubyFloat(value);
    jvalue params[3];
    params[0].l = jruby::getRuntime();
    params[1].j = p2j(f);
    params[2].d = value;

    jobject rubyFloat = env->CallStaticObjectMethodA(JRuby_class, JRuby_newFloat, params);
    f->obj = env->NewGlobalRef(rubyFloat);

    return f->asValue();
}