diff --git a/modules/overrungl.core/src/main/java/overrungl/Addressable.java b/modules/overrungl.core/src/main/java/overrungl/Addressable.java
index 71a6e577..587fdd00 100644
--- a/modules/overrungl.core/src/main/java/overrungl/Addressable.java
+++ b/modules/overrungl.core/src/main/java/overrungl/Addressable.java
@@ -24,6 +24,7 @@
* @author squid233
* @since 0.1.0
*/
+@Deprecated(since = "0.1.0")
@FunctionalInterface
public interface Addressable {
/**
diff --git a/modules/overrungl.core/src/main/java/overrungl/ArrayPointer.java b/modules/overrungl.core/src/main/java/overrungl/ArrayPointer.java
index 256d9380..c51606f2 100644
--- a/modules/overrungl.core/src/main/java/overrungl/ArrayPointer.java
+++ b/modules/overrungl.core/src/main/java/overrungl/ArrayPointer.java
@@ -24,6 +24,7 @@
* @author squid233
* @since 0.1.0
*/
+@Deprecated(since = "0.1.0")
public interface ArrayPointer extends Addressable {
/**
* {@return the count of the elements in this array}
diff --git a/modules/overrungl.core/src/main/java/overrungl/Callback.java b/modules/overrungl.core/src/main/java/overrungl/Callback.java
index f2083fd1..3436429b 100644
--- a/modules/overrungl.core/src/main/java/overrungl/Callback.java
+++ b/modules/overrungl.core/src/main/java/overrungl/Callback.java
@@ -32,6 +32,7 @@
* @author squid233
* @since 0.1.0
*/
+@Deprecated(since = "0.1.0")
public interface Callback {
/**
* Gets the address with the given arena.
diff --git a/modules/overrungl.core/src/main/java/overrungl/Pointer.java b/modules/overrungl.core/src/main/java/overrungl/Pointer.java
index ff25835d..96c74e1b 100644
--- a/modules/overrungl.core/src/main/java/overrungl/Pointer.java
+++ b/modules/overrungl.core/src/main/java/overrungl/Pointer.java
@@ -25,6 +25,7 @@
* @author squid233
* @since 0.1.0
*/
+@Deprecated(since = "0.1.0")
public class Pointer implements Addressable {
/**
* The pointer address.
diff --git a/modules/overrungl.core/src/main/java/overrungl/Struct.java b/modules/overrungl.core/src/main/java/overrungl/Struct.java
index 3cc7769d..b7f1a27d 100644
--- a/modules/overrungl.core/src/main/java/overrungl/Struct.java
+++ b/modules/overrungl.core/src/main/java/overrungl/Struct.java
@@ -25,6 +25,7 @@
* @author squid233
* @since 0.1.0
*/
+@Deprecated(since = "0.1.0")
public class Struct extends Pointer {
/**
* The memory layout of this struct.
diff --git a/modules/overrungl.core/src/main/java/overrungl/internal/Checks.java b/modules/overrungl.core/src/main/java/overrungl/internal/Checks.java
deleted file mode 100644
index dbff6bfa..00000000
--- a/modules/overrungl.core/src/main/java/overrungl/internal/Checks.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Overrun Organization
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- */
-
-package overrungl.internal;
-
-/**
- * @author squid233
- * @since 0.1.0
- */
-public final class Checks {
- public static void arraySize(byte[] arr, int size) {
- if (arr == null) {
- throw new IllegalArgumentException("Expected size " + size + ", got null");
- }
- if (arr.length != size) {
- throw new IllegalArgumentException("Expected size " + size + ", got " + arr.length);
- }
- }
-}
diff --git a/modules/overrungl.core/src/main/java/overrungl/internal/Exceptions.java b/modules/overrungl.core/src/main/java/overrungl/internal/Exceptions.java
index 7bfd1fd7..09bc87fe 100644
--- a/modules/overrungl.core/src/main/java/overrungl/internal/Exceptions.java
+++ b/modules/overrungl.core/src/main/java/overrungl/internal/Exceptions.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2023 Overrun Organization
+ * Copyright (c) 2023-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -22,6 +22,7 @@
* @author squid233
* @since 0.1.0
*/
+@Deprecated(since = "0.1.0")
public final class Exceptions {
/**
* {@link IllegalStateException}
diff --git a/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java b/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java
index ecff6979..a37ae62c 100644
--- a/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java
+++ b/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java
@@ -97,16 +97,6 @@ public static String unboundPointerString(MemorySegment segment, int index) {
return reinterpreting(segment, index, str -> MemoryUtil.strlen(str) + 1).getString(0);
}
- /**
- * Converts the segment into a string.
- *
- * @param segment the segment
- * @return the string
- */
- public static String getString(MemorySegment segment) {
- return segment.reinterpret(MemoryUtil.strlen(segment) + 1).getString(0);
- }
-
/**
* Generates a string for unknown token.
*
diff --git a/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java b/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java
index c9fdb7c8..7d4a40fc 100644
--- a/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java
+++ b/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,6 +39,7 @@
* @see Configurations#DEBUG_STACK
* @since 0.1.0
*/
+@Deprecated(since = "0.1.0")
public sealed class MemoryStack extends Pointer implements Arena {
private static final boolean DEBUG = Configurations.DEBUG.get();
private static final boolean DEBUG_STACK = Configurations.DEBUG_STACK.get();
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java
index 134a1ca2..cc542346 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java
@@ -19,7 +19,6 @@
import org.jetbrains.annotations.Nullable;
import overrungl.internal.RuntimeHelper;
import overrungl.util.MemoryStack;
-import overrungl.util.MemoryUtil;
import overrungl.util.value.Pair;
import overrungl.util.value.Quad;
import overrungl.util.value.Triplet;
@@ -1204,8 +1203,8 @@ public static MemorySegment nsetErrorCallback(MemorySegment callback) {
* @return The previously set callback, or {@link MemorySegment#NULL NULL} if no callback was set.
* @see #nsetErrorCallback(MemorySegment) nsetErrorCallback
*/
- public static MemorySegment setErrorCallback(@Nullable IGLFWErrorFun callback) {
- return nsetErrorCallback(callback != null ? callback.address(Arena.global()) : MemorySegment.NULL);
+ public static MemorySegment setErrorCallback(@Nullable GLFWErrorFun callback) {
+ return nsetErrorCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL);
}
/**
@@ -1694,7 +1693,7 @@ public static MemorySegment getMonitorUserPointer(MemorySegment monitor) {
* library had not been initialized.
* @glfw.callback_signature
{@code void function_name(GLFWmonitor* monitor, int event)}
* For more information about the callback parameters, see the
- * {@link IGLFWMonitorFun function pointer type}.
+ * {@link GLFWMonitorFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
*/
@@ -1715,8 +1714,8 @@ public static MemorySegment nsetMonitorCallback(MemorySegment callback) {
* library had not been initialized.
* @see #nsetMonitorCallback(MemorySegment) nsetMonitorCallback
*/
- public static MemorySegment setMonitorCallback(@Nullable IGLFWMonitorFun callback) {
- return nsetMonitorCallback(callback != null ? callback.address(Arena.global()) : MemorySegment.NULL);
+ public static MemorySegment setMonitorCallback(@Nullable GLFWMonitorFun callback) {
+ return nsetMonitorCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL);
}
/**
@@ -3427,7 +3426,7 @@ public static MemorySegment getWindowUserPointer(MemorySegment window) {
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, int xpos, int ypos)}
* For more information about the callback parameters, see the
- * {@link IGLFWWindowPosFun function pointer type}.
+ * {@link GLFWWindowPosFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.remark Wayland: This callback will never be called, as there is no way for
* an application to know its global position.
@@ -3451,8 +3450,8 @@ public static MemorySegment nsetWindowPosCallback(MemorySegment window, MemorySe
* library had not been initialized.
* @see #nsetWindowPosCallback(MemorySegment, MemorySegment) nsetWindowPosCallback
*/
- public static MemorySegment setWindowPosCallback(MemorySegment window, @Nullable IGLFWWindowPosFun callback) {
- return nsetWindowPosCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setWindowPosCallback(MemorySegment window, @Nullable GLFWWindowPosFun callback) {
+ return nsetWindowPosCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -3469,7 +3468,7 @@ public static MemorySegment setWindowPosCallback(MemorySegment window, @Nullable
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, int width, int height)}
* For more information about the callback parameters, see the
- * {@link IGLFWWindowSizeFun function pointer type}.
+ * {@link GLFWWindowSizeFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
*/
@@ -3491,8 +3490,8 @@ public static MemorySegment nsetWindowSizeCallback(MemorySegment window, MemoryS
* library had not been initialized.
* @see #nsetWindowSizeCallback(MemorySegment, MemorySegment) nsetWindowSizeCallback
*/
- public static MemorySegment setWindowSizeCallback(MemorySegment window, @Nullable IGLFWWindowSizeFun callback) {
- return nsetWindowSizeCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setWindowSizeCallback(MemorySegment window, @Nullable GLFWWindowSizeFun callback) {
+ return nsetWindowSizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -3514,7 +3513,7 @@ public static MemorySegment setWindowSizeCallback(MemorySegment window, @Nullabl
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window)}
* For more information about the callback parameters, see the
- * {@link IGLFWWindowCloseFun function pointer type}.
+ * {@link GLFWWindowCloseFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.remark macOS: Selecting Quit from the application menu will trigger the
* close callback for all windows.
@@ -3538,8 +3537,8 @@ public static MemorySegment nsetWindowCloseCallback(MemorySegment window, Memory
* library had not been initialized.
* @see #nsetWindowCloseCallback(MemorySegment, MemorySegment) nsetWindowCloseCallback
*/
- public static MemorySegment setWindowCloseCallback(MemorySegment window, @Nullable IGLFWWindowCloseFun callback) {
- return nsetWindowCloseCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setWindowCloseCallback(MemorySegment window, @Nullable GLFWWindowCloseFun callback) {
+ return nsetWindowCloseCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -3560,7 +3559,7 @@ public static MemorySegment setWindowCloseCallback(MemorySegment window, @Nullab
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window);}
* For more information about the callback parameters, see the
- * {@link IGLFWWindowRefreshFun function pointer type}.
+ * {@link GLFWWindowRefreshFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
*/
@@ -3582,8 +3581,8 @@ public static MemorySegment nsetWindowRefreshCallback(MemorySegment window, Memo
* library had not been initialized.
* @see #nsetWindowRefreshCallback(MemorySegment, MemorySegment) nsetWindowRefreshCallback
*/
- public static MemorySegment setWindowRefreshCallback(MemorySegment window, @Nullable IGLFWWindowRefreshFun callback) {
- return nsetWindowRefreshCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setWindowRefreshCallback(MemorySegment window, @Nullable GLFWWindowRefreshFun callback) {
+ return nsetWindowRefreshCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -3605,7 +3604,7 @@ public static MemorySegment setWindowRefreshCallback(MemorySegment window, @Null
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, int focused)}
* For more information about the callback parameters, see the
- * {@link IGLFWWindowFocusFun function pointer type}.
+ * {@link GLFWWindowFocusFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
*/
@@ -3627,8 +3626,8 @@ public static MemorySegment nsetWindowFocusCallback(MemorySegment window, Memory
* library had not been initialized.
* @see #nsetWindowFocusCallback(MemorySegment, MemorySegment) nsetWindowFocusCallback
*/
- public static MemorySegment setWindowFocusCallback(MemorySegment window, @Nullable IGLFWWindowFocusFun callback) {
- return nsetWindowFocusCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setWindowFocusCallback(MemorySegment window, @Nullable GLFWWindowFocusFun callback) {
+ return nsetWindowFocusCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -3644,7 +3643,7 @@ public static MemorySegment setWindowFocusCallback(MemorySegment window, @Nullab
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, int iconified)}
* For more information about the callback parameters, see the
- * {@link IGLFWWindowIconifyFun function pointer type}.
+ * {@link GLFWWindowIconifyFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.remark Wayland: The XDG-shell protocol has no event for iconification, so
* this callback will never be called.
@@ -3668,8 +3667,8 @@ public static MemorySegment nsetWindowIconifyCallback(MemorySegment window, Memo
* library had not been initialized.
* @see #nsetWindowIconifyCallback(MemorySegment, MemorySegment) nsetWindowIconifyCallback
*/
- public static MemorySegment setWindowIconifyCallback(MemorySegment window, @Nullable IGLFWWindowIconifyFun callback) {
- return nsetWindowIconifyCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setWindowIconifyCallback(MemorySegment window, @Nullable GLFWWindowIconifyFun callback) {
+ return nsetWindowIconifyCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -3685,7 +3684,7 @@ public static MemorySegment setWindowIconifyCallback(MemorySegment window, @Null
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, int maximized)}
* For more information about the callback parameters, see the
- * {@link IGLFWWindowMaximizeFun function pointer type}.
+ * {@link GLFWWindowMaximizeFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
*/
@@ -3707,8 +3706,8 @@ public static MemorySegment nsetWindowMaximizeCallback(MemorySegment window, Mem
* library had not been initialized.
* @see #nsetWindowMaximizeCallback(MemorySegment, MemorySegment) nsetWindowMaximizeCallback
*/
- public static MemorySegment setWindowMaximizeCallback(MemorySegment window, @Nullable IGLFWWindowMaximizeFun callback) {
- return nsetWindowMaximizeCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setWindowMaximizeCallback(MemorySegment window, @Nullable GLFWWindowMaximizeFun callback) {
+ return nsetWindowMaximizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -3724,7 +3723,7 @@ public static MemorySegment setWindowMaximizeCallback(MemorySegment window, @Nul
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, int width, int height)}
* For more information about the callback parameters, see the
- * {@link IGLFWFramebufferSizeFun function pointer type}.
+ * {@link GLFWFramebufferSizeFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
*/
@@ -3746,8 +3745,8 @@ public static MemorySegment nsetFramebufferSizeCallback(MemorySegment window, Me
* library had not been initialized.
* @see #nsetFramebufferSizeCallback(MemorySegment, MemorySegment) nsetFramebufferSizeCallback
*/
- public static MemorySegment setFramebufferSizeCallback(MemorySegment window, @Nullable IGLFWFramebufferSizeFun callback) {
- return nsetFramebufferSizeCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setFramebufferSizeCallback(MemorySegment window, @Nullable GLFWFramebufferSizeFun callback) {
+ return nsetFramebufferSizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -3763,7 +3762,7 @@ public static MemorySegment setFramebufferSizeCallback(MemorySegment window, @Nu
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, float xscale, float yscale)}
* For more information about the callback parameters, see the
- * {@link IGLFWWindowContentScaleFun function pointer type}.
+ * {@link GLFWWindowContentScaleFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
* @see #ngetWindowContentScale(MemorySegment, MemorySegment, MemorySegment) getWindowContentScale
@@ -3786,8 +3785,8 @@ public static MemorySegment nsetWindowContentScaleCallback(MemorySegment window,
* library had not been initialized.
* @see #nsetWindowContentScaleCallback(MemorySegment, MemorySegment) nsetWindowContentScaleCallback
*/
- public static MemorySegment setWindowContentScaleCallback(MemorySegment window, @Nullable IGLFWWindowContentScaleFun callback) {
- return nsetWindowContentScaleCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setWindowContentScaleCallback(MemorySegment window, @Nullable GLFWWindowContentScaleFun callback) {
+ return nsetWindowContentScaleCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -4512,7 +4511,7 @@ public static void setCursor(MemorySegment window, MemorySegment cursor) {
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, int key, int scancode, int action, int mods)}
* For more information about the callback parameters, see the
- * {@link IGLFWKeyFun function pointer type}.
+ * {@link GLFWKeyFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
*/
@@ -4534,8 +4533,8 @@ public static MemorySegment nsetKeyCallback(MemorySegment window, MemorySegment
* library had not been initialized.
* @see #nsetKeyCallback(MemorySegment, MemorySegment) nsetKeyCallback
*/
- public static MemorySegment setKeyCallback(MemorySegment window, @Nullable IGLFWKeyFun callback) {
- return nsetKeyCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setKeyCallback(MemorySegment window, @Nullable GLFWKeyFun callback) {
+ return nsetKeyCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -4563,7 +4562,7 @@ public static MemorySegment setKeyCallback(MemorySegment window, @Nullable IGLFW
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, unsigned int codepoint)}
* For more information about the callback parameters, see the
- * {@link IGLFWCharFun function pointer type}.
+ * {@link GLFWCharFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
*/
@@ -4585,8 +4584,8 @@ public static MemorySegment nsetCharCallback(MemorySegment window, MemorySegment
* library had not been initialized.
* @see #nsetCharCallback(MemorySegment, MemorySegment) nsetCharCallback
*/
- public static MemorySegment setCharCallback(MemorySegment window, @Nullable IGLFWCharFun callback) {
- return nsetCharCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setCharCallback(MemorySegment window, @Nullable GLFWCharFun callback) {
+ return nsetCharCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -4608,7 +4607,7 @@ public static MemorySegment setCharCallback(MemorySegment window, @Nullable IGLF
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, int button, int action, int mods)}
* For more information about the callback parameters, see the
- * {@link IGLFWMouseButtonFun function pointer type}.
+ * {@link GLFWMouseButtonFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
*/
@@ -4630,8 +4629,8 @@ public static MemorySegment nsetMouseButtonCallback(MemorySegment window, Memory
* library had not been initialized.
* @see #nsetMouseButtonCallback(MemorySegment, MemorySegment) nsetMouseButtonCallback
*/
- public static MemorySegment setMouseButtonCallback(MemorySegment window, @Nullable IGLFWMouseButtonFun callback) {
- return nsetMouseButtonCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setMouseButtonCallback(MemorySegment window, @Nullable GLFWMouseButtonFun callback) {
+ return nsetMouseButtonCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -4649,7 +4648,7 @@ public static MemorySegment setMouseButtonCallback(MemorySegment window, @Nullab
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, double xpos, double ypos);}
* For more information about the callback parameters, see the
- * {@link IGLFWCursorPosFun function pointer type}.
+ * {@link GLFWCursorPosFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
*/
@@ -4671,8 +4670,8 @@ public static MemorySegment nsetCursorPosCallback(MemorySegment window, MemorySe
* library had not been initialized.
* @see #nsetCursorPosCallback(MemorySegment, MemorySegment) nsetCursorPosCallback
*/
- public static MemorySegment setCursorPosCallback(MemorySegment window, @Nullable IGLFWCursorPosFun callback) {
- return nsetCursorPosCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setCursorPosCallback(MemorySegment window, @Nullable GLFWCursorPosFun callback) {
+ return nsetCursorPosCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -4689,7 +4688,7 @@ public static MemorySegment setCursorPosCallback(MemorySegment window, @Nullable
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, int entered)}
* For more information about the callback parameters, see the
- * {@link IGLFWCursorEnterFun function pointer type}.
+ * {@link GLFWCursorEnterFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
*/
@@ -4711,8 +4710,8 @@ public static MemorySegment nsetCursorEnterCallback(MemorySegment window, Memory
* library had not been initialized.
* @see #nsetCursorEnterCallback(MemorySegment, MemorySegment) nsetCursorEnterCallback
*/
- public static MemorySegment setCursorEnterCallback(MemorySegment window, @Nullable IGLFWCursorEnterFun callback) {
- return nsetCursorEnterCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setCursorEnterCallback(MemorySegment window, @Nullable GLFWCursorEnterFun callback) {
+ return nsetCursorEnterCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -4732,7 +4731,7 @@ public static MemorySegment setCursorEnterCallback(MemorySegment window, @Nullab
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, double xoffset, double yoffset)}
* For more information about the callback parameters, see the
- * {@link IGLFWScrollFun function pointer type}.
+ * {@link GLFWScrollFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
*/
@@ -4754,8 +4753,8 @@ public static MemorySegment nsetScrollCallback(MemorySegment window, MemorySegme
* library had not been initialized.
* @see #nsetScrollCallback(MemorySegment, MemorySegment) nsetScrollCallback
*/
- public static MemorySegment setScrollCallback(MemorySegment window, @Nullable IGLFWScrollFun callback) {
- return nsetScrollCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setScrollCallback(MemorySegment window, @Nullable GLFWScrollFun callback) {
+ return nsetScrollCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -4776,7 +4775,7 @@ public static MemorySegment setScrollCallback(MemorySegment window, @Nullable IG
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(GLFWwindow* window, int path_count, const char* paths[])}
* For more information about the callback parameters, see the
- * {@link IGLFWDropFun function pointer type}.
+ * {@link GLFWDropFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.remark Wayland: File drop is currently unimplemented.
* @glfw.thread_safety This function must only be called from the main thread.
@@ -4799,8 +4798,8 @@ public static MemorySegment nsetDropCallback(MemorySegment window, MemorySegment
* library had not been initialized.
* @see #nsetDropCallback(MemorySegment, MemorySegment) nsetDropCallback
*/
- public static MemorySegment setDropCallback(MemorySegment window, @Nullable IGLFWDropFun callback) {
- return nsetDropCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL);
+ public static MemorySegment setDropCallback(MemorySegment window, @Nullable GLFWDropFun callback) {
+ return nsetDropCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL);
}
/**
@@ -5215,7 +5214,7 @@ public static boolean joystickIsGamepad(int jid) {
* library had not been initialized.
* @glfw.callback_signature {@code void function_name(int jid, int event)}
* For more information about the callback parameters, see the
- * {@link IGLFWJoystickFun function pointer type}.
+ * {@link GLFWJoystickFun function pointer type}.
* @glfw.errors Possible errors include {@link #NOT_INITIALIZED}.
* @glfw.thread_safety This function must only be called from the main thread.
*/
@@ -5236,8 +5235,8 @@ public static MemorySegment nsetJoystickCallback(MemorySegment callback) {
* library had not been initialized.
* @see #nsetJoystickCallback(MemorySegment) nsetJoystickCallback
*/
- public static MemorySegment setJoystickCallback(@Nullable IGLFWJoystickFun callback) {
- return nsetJoystickCallback(callback != null ? callback.address(Arena.global()) : MemorySegment.NULL);
+ public static MemorySegment setJoystickCallback(@Nullable GLFWJoystickFun callback) {
+ return nsetJoystickCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL);
}
/**
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java
index 05e1b152..8aebde72 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -18,8 +18,8 @@
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
/**
* The GLFW window callbacks.
@@ -28,7 +28,7 @@
* @since 0.1.0
*/
public final class GLFWCallbacks {
- private static final Map ARENA_MAP = new HashMap<>();
+ private static final Map ARENA_MAP = new ConcurrentHashMap<>();
private GLFWCallbacks() {
//no instance
@@ -42,7 +42,7 @@ private GLFWCallbacks() {
* @return the arena.
*/
public static Arena create(MemorySegment window) {
- return ARENA_MAP.computeIfAbsent(window, k -> Arena.ofConfined());
+ return ARENA_MAP.computeIfAbsent(window, _ -> Arena.ofConfined());
}
/**
@@ -52,6 +52,22 @@ public static Arena create(MemorySegment window) {
*/
public static void free(MemorySegment window) {
if (ARENA_MAP.containsKey(window)) {
+ GLFW.setCharCallback(window, null);
+ GLFW.setCursorEnterCallback(window, null);
+ GLFW.setCursorPosCallback(window, null);
+ GLFW.setDropCallback(window, null);
+ GLFW.setFramebufferSizeCallback(window, null);
+ GLFW.setKeyCallback(window, null);
+ GLFW.setMouseButtonCallback(window, null);
+ GLFW.setScrollCallback(window, null);
+ GLFW.setWindowCloseCallback(window, null);
+ GLFW.setWindowContentScaleCallback(window, null);
+ GLFW.setWindowFocusCallback(window, null);
+ GLFW.setWindowIconifyCallback(window, null);
+ GLFW.setWindowMaximizeCallback(window, null);
+ GLFW.setWindowPosCallback(window, null);
+ GLFW.setWindowRefreshCallback(window, null);
+ GLFW.setWindowSizeCallback(window, null);
ARENA_MAP.remove(window).close();
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCharFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCharFun.java
similarity index 59%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCharFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCharFun.java
index 63b9cb01..5b15487b 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCharFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCharFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for Unicode character callbacks.
* A Unicode character callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWCharFun::invoke)
- * void functionName(MemorySegment window, int codepoint);
+ * void functionName(MemorySegment window, int codepoint); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWCharFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWCharFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for Unicode character callbacks.
@@ -48,15 +45,11 @@ public interface IGLFWCharFun extends Callback {
* @param window The window that received the event.
* @param codepoint The Unicode code point of the character.
*/
+ @Stub
void invoke(MemorySegment window, int codepoint);
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWCharFun.class, "invoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorEnterFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorEnterFun.java
similarity index 62%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorEnterFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorEnterFun.java
index 69e7219a..169e6bce 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorEnterFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorEnterFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for cursor enter/leave callbacks.
* A cursor enter/leave callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWCursorEnterFun::invoke)
- * void functionName(MemorySegment window, boolean entered);
+ * void functionName(MemorySegment window, boolean entered); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWCursorEnterFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWCursorEnterFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for cursor enter/leave callbacks.
@@ -51,17 +48,20 @@ public interface IGLFWCursorEnterFun extends Callback {
*/
void invoke(MemorySegment window, boolean entered);
+ /**
+ * The function pointer type for cursor enter/leave callbacks.
+ *
+ * @param window The window that received the event.
+ * @param entered {@code true} if the cursor entered the window's content
+ * area, or {@code false} if it left it.
+ */
+ @Stub
default void ninvoke(MemorySegment window, int entered) {
invoke(window, entered != GLFW.FALSE);
}
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWCursorEnterFun.class, "ninvoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorPosFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorPosFun.java
similarity index 63%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorPosFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorPosFun.java
index 27dd7060..d8bba273 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorPosFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorPosFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for cursor position callbacks. A cursor
* position callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWCursorPosFun::invoke)
- * void functionName(MemorySegment window, double xpos, double ypos);
+ * void functionName(MemorySegment window, double xpos, double ypos); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWCursorPosFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWCursorPosFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for cursor position callbacks.
@@ -49,15 +46,11 @@ public interface IGLFWCursorPosFun extends Callback {
* @param xpos The new cursor x-coordinate, relative to the left edge of the content area.
* @param ypos The new cursor y-coordinate, relative to the top edge of the content area.
*/
+ @Stub
void invoke(MemorySegment window, double xpos, double ypos);
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWCursorPosFun.class, "invoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWDropFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWDropFun.java
similarity index 63%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWDropFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWDropFun.java
index 6d26f956..2b13bc8c 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWDropFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWDropFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,22 +16,17 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
import overrungl.internal.RuntimeHelper;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for path drop callbacks. A path drop
* callback function has the following signature:
- * {@snippet lang=java:
- * @Invoker(IGLFWDropFun::invoke)
- * void functionName(MemorySegment window, String[] paths);
+ * {@snippet lang = java:
+ * void functionName(MemorySegment window, String[] paths); // @link regex="functionName" target="#invoke"
* }
* Pointer lifetime
* The path array and its strings are valid until the callback function returns.
@@ -41,29 +36,34 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWDropFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.ADDRESS);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWDropFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for path drop callbacks.
*
- * @param window The window that received the event.
- * @param paths The UTF-8 encoded file and/or directory path names.
+ * @param window The window that received the event.
+ * @param paths The UTF-8 encoded file and/or directory path names.
*/
void invoke(MemorySegment window, String[] paths);
+ /**
+ * The function pointer type for path drop callbacks.
+ *
+ * @param window The window that received the event.
+ * @param pathCount The number of dropped paths.
+ * @param paths The UTF-8 encoded file and/or directory path names.
+ */
+ @Stub
default void ninvoke(MemorySegment window, int pathCount, MemorySegment paths) {
invoke(window, RuntimeHelper.toUnboundedArray(paths, new String[pathCount]));
}
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWDropFun.class, "ninvoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorCallback.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorCallback.java
index a96b6c37..94794c3d 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorCallback.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorCallback.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -17,13 +17,12 @@
package overrungl.glfw;
import overrungl.OverrunGL;
-import overrungl.internal.Exceptions;
import java.io.PrintStream;
import java.util.function.Consumer;
/**
- * The {@linkplain IGLFWErrorFun GLFW error callback} creator.
+ * The {@linkplain GLFWErrorFun GLFW error callback} creator.
*
* @author squid233
* @since 0.1.0
@@ -34,48 +33,48 @@ private GLFWErrorCallback() {
}
/**
- * {@return a {@link IGLFWErrorFun} instance that throws an {@link IllegalStateException} when an error occurs}
+ * {@return a {@link GLFWErrorFun } instance that throws an {@link IllegalStateException} when an error occurs}
*/
- public static IGLFWErrorFun createThrow() {
+ public static GLFWErrorFun createThrow() {
return (errorCode, description) -> {
- throw Exceptions.ISE. "GLFW error [0x\{ Integer.toHexString(errorCode) }]: \{ description }" ;
+ throw new IllegalStateException(STR."GLFW error [0x\{Integer.toHexString(errorCode)}]: \{description}");
};
}
/**
- * {@return a {@link IGLFWErrorFun} instance that logs a message when an error occurs}
+ * {@return a {@link GLFWErrorFun } instance that logs a message when an error occurs}
*
* @param logger the logger function.
*/
- public static IGLFWErrorFun createLog(Consumer logger) {
+ public static GLFWErrorFun createLog(Consumer logger) {
return (errorCode, description) -> {
var sb = new StringBuilder(512);
- sb.append(STR. "[OverrunGL] GLFW \{ GLFW.getErrorString(errorCode) } error: \{ description }\n" );
+ sb.append(STR."[OverrunGL] GLFW \{GLFW.getErrorString(errorCode)} error: \{description}\n");
var stack = Thread.currentThread().getStackTrace();
for (int i = 3; i < stack.length; i++) {
- sb.append(STR. " at \{ stack[i] }\n" );
+ sb.append(STR." at \{stack[i]}\n");
}
logger.accept(sb.toString());
};
}
/**
- * {@return a {@link IGLFWErrorFun} instance that prints a message when an error occurs}
+ * {@return a {@link GLFWErrorFun } instance that prints a message when an error occurs}
*
* @param stream the logger stream.
* @see #createPrint()
*/
- public static IGLFWErrorFun createPrint(PrintStream stream) {
+ public static GLFWErrorFun createPrint(PrintStream stream) {
return createLog(stream::println);
}
/**
- * {@return a {@link IGLFWErrorFun} instance that prints a message to
+ * {@return a {@link GLFWErrorFun } instance that prints a message to
* {@link OverrunGL#apiLogger() default library logger} when an error occurs}
*
* @see #createPrint(PrintStream)
*/
- public static IGLFWErrorFun createPrint() {
+ public static GLFWErrorFun createPrint() {
return createLog(OverrunGL.apiLogger());
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWErrorFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java
similarity index 62%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWErrorFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java
index b7932e54..93a333ed 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWErrorFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,23 +16,19 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Unmarshal;
+import overrun.marshal.Upcall;
+import overrun.marshal.gen.SizedSeg;
import overrungl.NativeType;
-import overrungl.internal.RuntimeHelper;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for error callbacks. An error callback
* function has the following signature:
- * {@snippet lang=java:
- * @Invoker(IGLFWErrorFun::invoke)
- * void callbackName(int errorCode, String description);
+ * {@snippet lang = java:
+ * void callbackName(int errorCode, String description); // @link regex="functionName" target="#invoke"
* }
* Pointer lifetime
* The error description string is valid until the callback
@@ -43,9 +39,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWErrorFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.JAVA_INT, ValueLayout.ADDRESS);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWErrorFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for error callbacks.
@@ -55,8 +53,16 @@ public interface IGLFWErrorFun extends Callback {
*/
void invoke(int errorCode, String description);
- default void ninvoke(int errorCode, @NativeType("const char*") MemorySegment description) {
- invoke(errorCode, RuntimeHelper.getString(description));
+ /**
+ * The function pointer type for error callbacks.
+ *
+ * @param errorCode An error code.
+ * Future releases may add more error codes.
+ * @param description A UTF-8 encoded string describing the error.
+ */
+ @Stub
+ default void ninvoke(int errorCode, @NativeType("const char*") @SizedSeg(Unmarshal.STR_SIZE) MemorySegment description) {
+ invoke(errorCode, Unmarshal.unmarshalAsString(description));
}
/**
@@ -69,12 +75,7 @@ default MemorySegment set() {
}
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWErrorFun.class, "ninvoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWFramebufferSizeFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWFramebufferSizeFun.java
similarity index 62%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWFramebufferSizeFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWFramebufferSizeFun.java
index 5078dbd8..2dffce53 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWFramebufferSizeFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWFramebufferSizeFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for framebuffer size callbacks.
* A framebuffer size callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWFramebufferSizeFun::invoke)
- * void functionName(MemorySegment window, int width, int height);
+ * void functionName(MemorySegment window, int width, int height); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWFramebufferSizeFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWFramebufferSizeFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for framebuffer size callbacks.
@@ -49,15 +46,11 @@ public interface IGLFWFramebufferSizeFun extends Callback {
* @param width The new width, in pixels, of the framebuffer.
* @param height The new height, in pixels, of the framebuffer.
*/
+ @Stub
void invoke(MemorySegment window, int width, int height);
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWFramebufferSizeFun.class, "invoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWJoystickFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWJoystickFun.java
similarity index 60%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWJoystickFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWJoystickFun.java
index 169c97b7..fdfc0b20 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWJoystickFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWJoystickFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,20 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
+import java.lang.foreign.Arena;
+import java.lang.foreign.MemorySegment;
/**
* This is the function pointer type for joystick configuration callbacks.
* A joystick configuration callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWJoystickFun::invoke)
- * void functionName(int jid, int event);
+ * void functionName(int jid, int event); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -37,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWJoystickFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.JAVA_INT, ValueLayout.JAVA_INT);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWJoystickFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for joystick configuration callbacks.
@@ -48,15 +46,11 @@ public interface IGLFWJoystickFun extends Callback {
* @param event One of {@code CONNECTED} or {@code DISCONNECTED}. Future
* releases may add more events.
*/
+ @Stub
void invoke(int jid, int event);
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWJoystickFun.class, "invoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWKeyFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWKeyFun.java
similarity index 66%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWKeyFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWKeyFun.java
index 06b27857..bd87b937 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWKeyFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWKeyFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for keyboard key callbacks. A keyboard
* key callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWKeyFun::invoke)
- * void functionName(MemorySegment window, int key, int scancode, int action, int mods);
+ * void functionName(MemorySegment window, int key, int scancode, int action, int mods); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWKeyFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWKeyFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for keyboard key callbacks.
@@ -53,15 +50,11 @@ public interface IGLFWKeyFun extends Callback {
* @param mods Bit field describing which modifier keys
* were held down.
*/
+ @Stub
void invoke(MemorySegment window, int key, int scancode, int action, int mods);
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWKeyFun.class, "invoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMonitorFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMonitorFun.java
similarity index 60%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMonitorFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMonitorFun.java
index f4302297..d8e36873 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMonitorFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMonitorFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for monitor configuration callbacks.
* A monitor callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWMonitorFun::invoke)
- * void functionName(MemorySegment monitor, int event);
+ * void functionName(MemorySegment monitor, int event); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWMonitorFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWMonitorFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for monitor configuration callbacks.
@@ -49,15 +46,11 @@ public interface IGLFWMonitorFun extends Callback {
* @param event One of {@code CONNECTED} or {@code DISCONNECTED}. Future
* releases may add more events.
*/
+ @Stub
void invoke(MemorySegment monitor, int event);
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWMonitorFun.class, "invoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMouseButtonFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMouseButtonFun.java
similarity index 65%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMouseButtonFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMouseButtonFun.java
index e9349481..970d5a83 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMouseButtonFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMouseButtonFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for mouse button callback functions.
* A mouse button callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWMouseButtonFun::invoke)
- * void functionName(MemorySegment window, int button, int action, int mods);
+ * void functionName(MemorySegment window, int button, int action, int mods); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWMouseButtonFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWMouseButtonFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for mouse button callbacks.
@@ -50,15 +47,11 @@ public interface IGLFWMouseButtonFun extends Callback {
* @param action One of {@code PRESS} or {@code RELEASE}. Future releases may add more actions.
* @param mods Bit field describing which modifier keys were held down.
*/
+ @Stub
void invoke(MemorySegment window, int button, int action, int mods);
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWMouseButtonFun.class, "invoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWScrollFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWScrollFun.java
similarity index 61%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWScrollFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWScrollFun.java
index 2d8a4564..ee483d7e 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWScrollFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWScrollFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for scroll callbacks. A scroll callback
* function has the following signature:
* {@snippet :
- * @Invoker(IGLFWScrollFun::invoke)
- * void functionName(MemorySegment window, double xoffset, double yoffset);
+ * void functionName(MemorySegment window, double xoffset, double yoffset); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWScrollFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWScrollFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for scroll callbacks.
@@ -49,15 +46,11 @@ public interface IGLFWScrollFun extends Callback {
* @param xoffset The scroll offset along the x-axis.
* @param yoffset The scroll offset along the y-axis.
*/
+ @Stub
void invoke(MemorySegment window, double xoffset, double yoffset);
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWScrollFun.class, "invoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowCloseFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowCloseFun.java
similarity index 58%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowCloseFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowCloseFun.java
index e4747f44..128d295c 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowCloseFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowCloseFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for window close callbacks. A window
* close callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWWindowCloseFun::invoke)
- * void functionName(MemorySegment window);
+ * void functionName(MemorySegment window); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,24 +33,22 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWWindowCloseFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWWindowCloseFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for window close callbacks.
*
* @param window The window that the user attempted to close.
*/
+ @Stub
void invoke(MemorySegment window);
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWWindowCloseFun.class, "invoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowContentScaleFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowContentScaleFun.java
similarity index 62%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowContentScaleFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowContentScaleFun.java
index f640da18..b82ca1a3 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowContentScaleFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowContentScaleFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for window content scale callbacks.
* A window content scale callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWWindowContentScaleFun::invoke)
- * void functionName(MemorySegment window, float xscale, float yscale);
+ * void functionName(MemorySegment window, float xscale, float yscale); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWWindowContentScaleFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_FLOAT, ValueLayout.JAVA_FLOAT);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWWindowContentScaleFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for window content scale callbacks.
@@ -49,15 +46,11 @@ public interface IGLFWWindowContentScaleFun extends Callback {
* @param xscale The new x-axis content scale of the window.
* @param yscale The new y-axis content scale of the window.
*/
+ @Stub
void invoke(MemorySegment window, float xscale, float yscale);
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWWindowContentScaleFun.class, "invoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowFocusFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowFocusFun.java
similarity index 62%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowFocusFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowFocusFun.java
index 3b782ba2..be237d00 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowFocusFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowFocusFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for window focus callbacks. A window
* focus callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWWindowFocusFun::invoke)
- * void functionName(MemorySegment window, boolean focused);
+ * void functionName(MemorySegment window, boolean focused); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWWindowFocusFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWWindowFocusFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for window focus callbacks.
@@ -51,17 +48,20 @@ public interface IGLFWWindowFocusFun extends Callback {
*/
void invoke(MemorySegment window, boolean focused);
+ /**
+ * The function pointer type for window focus callbacks.
+ *
+ * @param window The window that gained or lost input focus.
+ * @param focused {@code true} if the window was given input focus, or
+ * {@code false} if it lost it.
+ */
+ @Stub
default void ninvoke(MemorySegment window, int focused) {
invoke(window, focused != GLFW.FALSE);
}
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWWindowFocusFun.class, "ninvoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowIconifyFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowIconifyFun.java
similarity index 62%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowIconifyFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowIconifyFun.java
index 2baa6750..34837046 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowIconifyFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowIconifyFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for window iconify callbacks. A window
* iconify callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWWindowIconifyFun::invoke)
- * void functionName(MemorySegment window, boolean iconified);
+ * void functionName(MemorySegment window, boolean iconified); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWWindowIconifyFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWWindowIconifyFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for window iconify callbacks.
@@ -51,17 +48,20 @@ public interface IGLFWWindowIconifyFun extends Callback {
*/
void invoke(MemorySegment window, boolean iconified);
+ /**
+ * The function pointer type for window iconify callbacks.
+ *
+ * @param window The window that was iconified or restored.
+ * @param iconified {@code true} if the window was iconified, or
+ * {@code false} if it was restored.
+ */
+ @Stub
default void ninvoke(MemorySegment window, int iconified) {
invoke(window, iconified != GLFW.FALSE);
}
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWWindowIconifyFun.class, "ninvoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowMaximizeFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowMaximizeFun.java
similarity index 62%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowMaximizeFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowMaximizeFun.java
index 8896c448..2d7f5b40 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowMaximizeFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowMaximizeFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for window maximize callbacks. A window
* maximize callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWWindowMaximizeFun::invoke)
- * void functionName(MemorySegment window, boolean maximized);
+ * void functionName(MemorySegment window, boolean maximized); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWWindowMaximizeFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWWindowMaximizeFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for window maximize callbacks.
@@ -51,17 +48,20 @@ public interface IGLFWWindowMaximizeFun extends Callback {
*/
void invoke(MemorySegment window, boolean maximized);
+ /**
+ * The function pointer type for window maximize callbacks.
+ *
+ * @param window The window that was maximized or restored.
+ * @param maximized {@code true} if the window was maximized, or
+ * {@code false} if it was restored.
+ */
+ @Stub
default void ninvoke(MemorySegment window, int maximized) {
invoke(window, maximized != GLFW.FALSE);
}
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWWindowMaximizeFun.class, "ninvoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowPosFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowPosFun.java
similarity index 59%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowPosFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowPosFun.java
index 3dd23e53..2d6c82c9 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowPosFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowPosFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
- * This is the function pointer type for window position callbacks.A window
- * position callback function has the following signature:
+ * This is the function pointer type for window position callbacks.
+ * A window position callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWWindowPosFun::invoke)
- * void callbackName(MemorySegment window, int xpos, int ypos);
+ * void callbackName(MemorySegment window, int xpos, int ypos); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWWindowPosFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWWindowPosFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for window position callbacks.
@@ -51,15 +48,11 @@ public interface IGLFWWindowPosFun extends Callback {
* @param ypos The new y-coordinate, in screen coordinates, of the
* upper-left corner of the content area of the window.
*/
+ @Stub
void invoke(MemorySegment window, int xpos, int ypos);
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWWindowPosFun.class, "invoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowRefreshFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowRefreshFun.java
similarity index 59%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowRefreshFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowRefreshFun.java
index ab966963..f4c3776f 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowRefreshFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowRefreshFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for window content refresh callbacks.
* A window content refresh callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWWindowRefreshFun::invoke)
- * void functionName(MemorySegment window);
+ * void functionName(MemorySegment window); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,24 +33,22 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWWindowRefreshFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWWindowRefreshFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for window content refresh callbacks.
*
* @param window The window whose content needs to be refreshed.
*/
+ @Stub
void invoke(MemorySegment window);
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWWindowRefreshFun.class, "invoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}
diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowSizeFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowSizeFun.java
similarity index 62%
rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowSizeFun.java
rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowSizeFun.java
index 9bbb49c6..05b88a99 100644
--- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowSizeFun.java
+++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowSizeFun.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022-2023 Overrun Organization
+ * Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -16,21 +16,16 @@
package overrungl.glfw;
-import overrungl.Callback;
+import overrun.marshal.Upcall;
-import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
/**
* This is the function pointer type for window size callbacks. A window size
* callback function has the following signature:
* {@snippet :
- * @Invoker(IGLFWWindowSizeFun::invoke)
- * void callbackName(MemorySegment window, int width, int height);
+ * void callbackName(MemorySegment window, int width, int height); // @link regex="functionName" target="#invoke"
* }
*
* @author squid233
@@ -38,9 +33,11 @@
* @since 0.1.0
*/
@FunctionalInterface
-public interface IGLFWWindowSizeFun extends Callback {
- FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT);
- MethodType MTYPE = DESC.toMethodType();
+public interface GLFWWindowSizeFun extends Upcall {
+ /**
+ * The type.
+ */
+ Type TYPE = Upcall.type();
/**
* The function pointer type for window size callbacks.
@@ -49,15 +46,11 @@ public interface IGLFWWindowSizeFun extends Callback {
* @param width The new width, in screen coordinates, of the window.
* @param height The new height, in screen coordinates, of the window.
*/
+ @Stub
void invoke(MemorySegment window, int width, int height);
@Override
- default FunctionDescriptor descriptor() {
- return DESC;
- }
-
- @Override
- default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException {
- return lookup.findVirtual(IGLFWWindowSizeFun.class, "invoke", MTYPE);
+ default MemorySegment stub(Arena arena) {
+ return TYPE.of(arena, this);
}
}