Exemplo n.º 1
0
  public static RubyClass createPointerClass(Ruby runtime, RubyModule module) {
    RubyClass pointerClass =
        module.defineClassUnder(
            "Pointer",
            module.getClass(AbstractMemory.ABSTRACT_MEMORY_RUBY_CLASS),
            RubyInstanceConfig.REIFY_RUBY_CLASSES
                ? new ReifyingAllocator(Pointer.class)
                : PointerAllocator.INSTANCE);

    pointerClass.defineAnnotatedMethods(Pointer.class);
    pointerClass.defineAnnotatedConstants(Pointer.class);
    pointerClass.setReifiedClass(Pointer.class);
    pointerClass.kindOf =
        new RubyModule.KindOf() {
          @Override
          public boolean isKindOf(IRubyObject obj, RubyModule type) {
            return obj instanceof Pointer && super.isKindOf(obj, type);
          }
        };

    module.defineClassUnder(
        "NullPointerError", runtime.getRuntimeError(), runtime.getRuntimeError().getAllocator());

    // Add Pointer::NULL as a constant
    Pointer nullPointer = new Pointer(runtime, pointerClass, new NullMemoryIO(runtime));
    pointerClass.setConstant("NULL", nullPointer);

    runtime
        .getNilClass()
        .addMethod("to_ptr", new NilToPointerMethod(runtime.getNilClass(), nullPointer));

    return pointerClass;
  }
Exemplo n.º 2
0
  public static RubyClass createConverterClass(Ruby runtime) {
    RubyClass converterc =
        runtime.defineClassUnder(
            "Converter", runtime.getClass("Data"), CONVERTER_ALLOCATOR, runtime.getEncoding());
    runtime.setConverter(converterc);
    converterc.index = ClassIndex.CONVERTER;
    converterc.setReifiedClass(RubyConverter.class);
    converterc.kindOf = new RubyModule.JavaClassKindOf(RubyConverter.class);

    converterc.defineAnnotatedMethods(RubyConverter.class);
    return converterc;
  }