Inceptum/launcher-gtk/src/main/java/io/gitlab/jfronny/inceptum/gtk/callback/GetItemCallback.java

25 lines
994 B
Java

package io.gitlab.jfronny.inceptum.gtk.callback;
import io.github.jwharm.javagi.CallbackGenerator;
import io.github.jwharm.javagi.Interop;
import org.jetbrains.annotations.ApiStatus;
import java.lang.foreign.Addressable;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.Linker;
import java.lang.foreign.MemoryAddress;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
@FunctionalInterface
public interface GetItemCallback {
Addressable upcall(MemoryAddress inst, int position);
@ApiStatus.Internal FunctionDescriptor DESCRIPTOR = FunctionDescriptor.of(Interop.valueLayout.ADDRESS, Interop.valueLayout.ADDRESS, Interop.valueLayout.C_INT);
@ApiStatus.Internal MethodHandle HANDLE = CallbackGenerator.getHandle(MethodHandles.lookup(), GetItemCallback.class, DESCRIPTOR);
default MemoryAddress toCallback() {
return Linker.nativeLinker().upcallStub(HANDLE.bindTo(this), DESCRIPTOR, Interop.getScope()).address();
}
}