Skip to content
squid233 edited this page May 4, 2024 · 1 revision

Defining a library

Use an interface or an abstract class to define functions.

C Definition

#include <stdio.h>
void helloWorld() { printf("Hello world!"); }

Compile and link it as a dynamic library.

Java Definition

interface MyLib {
  MyLib INSTANCE = Downcall.load(MethodHandles.lookup(), "example.dll");
  void helloWorld();
}

To detect multi-platform, see https://github.com/Over-Run/platform.

C Structures

See javadoc of StructAllocator for more information.

interface Point {
  StructAllocator<Point> OF = new StructAllocator(
    MethodHandles.lookup(),
    LayoutBuilder.struct().cInt("x").cInt("y").build()
  );

  int x();
  int y();
}
Clone this wiki locally