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.
@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.
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
}
}