Skip to content
/ jnr-invoke Public

Link to native C functions via JSR-292 MethodHandles

License

Notifications You must be signed in to change notification settings

jnr/jnr-invoke

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jnr-invoke Build Status

jnr-invoke is a java library for loading native libraries without writing JNI code by hand, or using tools such as SWIG.

Example

import com.kenai.jffi.Platform;
import jnr.invoke.*;

import java.lang.invoke.MethodHandle;

public class Getpid {
    public static void main(String[] args) throws Throwable {
        
        // Create a function signature for long getpid()
        Signature signature = Signature.getSignature(ResultType.primitive(NativeType.ULONG, long.class),
                new ParameterType[0], Signature.CDECL);
                            
        Library libc = Library.open(Platform.getPlatform().mapLibraryName("c"), Library.LAZY | Library.LOCAL);

        MethodHandle mh = Native.getMethodHandle(libc.findSymbol("getpid"), signature);
        System.out.println("pid = " + mh.invoke());
    }
}

About

Link to native C functions via JSR-292 MethodHandles

Resources

License

Stars

Watchers

Forks

Packages

No packages published