Beispiel #1
0
 @Override
 public void init(Ruby runtime, RubyModule ffi) {
   super.init(runtime, ffi);
   //
   // Hook up the MemoryPointer class if its not already there
   //
   synchronized (ffi) {
     if (ffi.fastGetClass("DynamicLibrary") == null) {
       DynamicLibrary.createDynamicLibraryClass(runtime, ffi);
     }
     if (ffi.fastGetClass("Invoker") == null) {
       JNAInvoker.createInvokerClass(runtime, ffi);
     }
     if (ffi.fastGetClass("VariadicInvoker") == null) {
       JNAVariadicInvoker.createVariadicInvokerClass(runtime, ffi);
     }
     ffi.defineModuleUnder("LastError").defineAnnotatedMethods(LastError.class);
   }
 }
Beispiel #2
0
  /**
   * Registers the StructLayout class in the JRuby runtime.
   *
   * @param runtime The JRuby runtime to register the new class in.
   * @return The new class
   */
  public static RubyClass createStructLayoutClass(Ruby runtime, RubyModule module) {
    RubyClass layoutClass =
        runtime.defineClassUnder(
            CLASS_NAME,
            module.fastGetClass("Type"),
            ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR,
            module);
    layoutClass.defineAnnotatedMethods(StructLayout.class);
    layoutClass.defineAnnotatedConstants(StructLayout.class);

    RubyClass arrayClass =
        runtime.defineClassUnder(
            "ArrayProxy",
            runtime.getObject(),
            ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR,
            layoutClass);
    arrayClass.includeModule(runtime.getEnumerable());
    arrayClass.defineAnnotatedMethods(ArrayProxy.class);

    RubyClass charArrayClass =
        runtime.defineClassUnder(
            "CharArrayProxy", arrayClass, ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR, layoutClass);
    charArrayClass.defineAnnotatedMethods(CharArrayProxy.class);

    RubyClass fieldClass =
        runtime.defineClassUnder(
            "Field", runtime.getObject(), FieldAllocator.INSTANCE, layoutClass);
    fieldClass.defineAnnotatedMethods(Field.class);

    RubyClass numberFieldClass =
        runtime.defineClassUnder("Number", fieldClass, NumberFieldAllocator.INSTANCE, layoutClass);
    numberFieldClass.defineAnnotatedMethods(NumberField.class);

    RubyClass enumFieldClass =
        runtime.defineClassUnder("Enum", fieldClass, EnumFieldAllocator.INSTANCE, layoutClass);
    enumFieldClass.defineAnnotatedMethods(EnumField.class);

    RubyClass stringFieldClass =
        runtime.defineClassUnder("String", fieldClass, StringFieldAllocator.INSTANCE, layoutClass);
    stringFieldClass.defineAnnotatedMethods(StringField.class);

    RubyClass pointerFieldClass =
        runtime.defineClassUnder(
            "Pointer", fieldClass, PointerFieldAllocator.INSTANCE, layoutClass);
    pointerFieldClass.defineAnnotatedMethods(PointerField.class);

    RubyClass functionFieldClass =
        runtime.defineClassUnder(
            "Function", fieldClass, FunctionFieldAllocator.INSTANCE, layoutClass);
    functionFieldClass.defineAnnotatedMethods(FunctionField.class);

    RubyClass innerStructFieldClass =
        runtime.defineClassUnder(
            "InnerStruct", fieldClass, InnerStructFieldAllocator.INSTANCE, layoutClass);
    innerStructFieldClass.defineAnnotatedMethods(InnerStructField.class);

    RubyClass arrayFieldClass =
        runtime.defineClassUnder("Array", fieldClass, ArrayFieldAllocator.INSTANCE, layoutClass);
    arrayFieldClass.defineAnnotatedMethods(ArrayField.class);

    RubyClass mappedFieldClass =
        runtime.defineClassUnder("Mapped", fieldClass, MappedFieldAllocator.INSTANCE, layoutClass);
    mappedFieldClass.defineAnnotatedMethods(MappedField.class);

    return layoutClass;
  }