Ejemplo n.º 1
0
extern "C" void
rb_str_modify(VALUE str)
{
    JLocalEnv env;
    jmethodID mid = getCachedMethodID(env, RubyString_class, "modify", "()V");

    env->CallVoidMethod(valueToObject(env, str), mid);
    checkExceptions(env);
}
Ejemplo n.º 2
0
extern "C" void
rb_define_const(VALUE module, const char* name, VALUE obj)
{
    JLocalEnv env;
    jmethodID mid = getMethodID(env, RubyModule_class, "defineConstant",
            "(Ljava/lang/String;Lorg/jruby/runtime/builtin/IRubyObject;)V");
    env->CallVoidMethod(valueToObject(env, module), mid, env->NewStringUTF(name), valueToObject(env, obj));
    checkExceptions(env);
}
Ejemplo n.º 3
0
extern "C" void
rb_define_alias(VALUE klass, const char* new_name, const char* old_name)
{
    JLocalEnv env;
    jmethodID mid = getCachedMethodID(env, RubyModule_class, "defineAlias",
            "(Ljava/lang/String;Ljava/lang/String;)V");
    env->CallVoidMethod(valueToObject(env, klass), mid, env->NewStringUTF(new_name),
            env->NewStringUTF(old_name));
    checkExceptions(env);
}
Ejemplo n.º 4
0
extern "C" VALUE
rb_str_resize(VALUE str, long size) {
    long length = (long) jruby_str_length(str);
    if (size != length) {
        JLocalEnv env;
        env->CallVoidMethod(valueToObject(env, str), RubyString_resize_method, (jint)size);
        checkExceptions(env);
        jruby_rstring(str)->len = size;
    }
    return str;
}
Ejemplo n.º 5
0
extern "C" void
rb_define_alloc_func(VALUE klass, VALUE (*fn)(VALUE))
{
    JLocalEnv env;

    jobject allocator = env->NewObject(NativeObjectAllocator_class,
            getMethodID(env, NativeObjectAllocator_class, "<init>", "(J)V"),
            p2j((void *) fn));
    checkExceptions(env);

    env->CallVoidMethod(valueToObject(env, klass), RubyClass_setAllocator_method, allocator);
}
Ejemplo n.º 6
0
extern "C" void
rb_define_method(VALUE klass, const char* meth, VALUE(*fn)(ANYARGS), int arity)
{
    JLocalEnv env;

    jmethodID JRuby_newMethod = getStaticMethodID(env, JRuby_class, "newMethod", "(Lorg/jruby/RubyModule;JI)Lorg/jruby/internal/runtime/methods/DynamicMethod;");
    jmethodID RubyModule_addMethod_method = getMethodID(env, RubyModule_class, "addMethod",
            "(Ljava/lang/String;Lorg/jruby/internal/runtime/methods/DynamicMethod;)V");

    jobject module = valueToObject(env, klass);
    env->CallVoidMethod(module, RubyModule_addMethod_method, env->NewStringUTF(meth),
            env->CallStaticObjectMethod(JRuby_class, JRuby_newMethod, module, (jlong)(intptr_t) fn, arity));
    checkExceptions(env);
}
Ejemplo n.º 7
0
extern "C" void
rb_define_singleton_method(VALUE object, const char* meth, VALUE(*fn)(ANYARGS), int arity)
{
    JLocalEnv env;

    jmethodID IRubyObject_getSingletonClass_method = getMethodID(env, IRubyObject_class, "getSingletonClass",
            "()Lorg/jruby/RubyClass;");
    jobject singleton = env->CallObjectMethod(valueToObject(env, object), IRubyObject_getSingletonClass_method);

    jmethodID JRuby_newMethod = getStaticMethodID(env, JRuby_class, "newMethod",
            "(Lorg/jruby/RubyModule;JI)Lorg/jruby/internal/runtime/methods/DynamicMethod;");
    jmethodID RubyModule_addMethod_method = getMethodID(env, RubyModule_class, "addMethod",
            "(Ljava/lang/String;Lorg/jruby/internal/runtime/methods/DynamicMethod;)V");

    env->CallVoidMethod(singleton, RubyModule_addMethod_method, env->NewStringUTF(meth),
            env->CallStaticObjectMethod(JRuby_class, JRuby_newMethod, singleton, (jlong)(intptr_t) fn, arity));
    checkExceptions(env);
}