Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 1.25 KB

File metadata and controls

38 lines (28 loc) · 1.25 KB

NativeLoader (Annotation API)

NativeLoader enables interface-based library bindings (JNA-style) with no manual code generation. It uses dynamic proxies to intercept calls and translate them on the fly.

Annotations

  • @Library: Specifies which library to load.
  • @NativeName: Overrides the method's resolved symbol name if it differs from the Java signature.

Method parameter and return types are resolved through TypeMapperRegistry (built-in primitives, String, CChar, WChar, custom mappers, …). Full mapping table: NativeTypes.md.

Usage Example

import io.github.undeffineddev.ffmkit.annotation.Library;
import io.github.undeffineddev.ffmkit.annotation.NativeName;
import io.github.undeffineddev.ffmkit.annotation.NativeLoader;

// Define an interface representing the target library
@Library("c")
public interface LibC {
    
    int puts(String text);
    
    @NativeName("strlen")
    int length(String text);
}

public class Main {
    public static void main(String[] args) {
        // Load library proxy instance
        LibC libc = NativeLoader.load(LibC.class);
        
        libc.puts("Hello from proxy interface!");
        int len = libc.length("Panama");
        System.out.println(len); // 6
    }
}