diff --git a/ffi/export.h b/ffi/export.h index c210373..31022f1 100644 --- a/ffi/export.h +++ b/ffi/export.h @@ -158,6 +158,7 @@ extern "C" { #endif MLLIB_PUBLIC(void mltonFramebufferSizeCallback (Int32 x0, Int32 x1);) +MLLIB_PUBLIC(void mltonCharCallback (Word32 x0);) #undef MLLIB_PRIVATE #undef MLLIB_PUBLIC diff --git a/ffi/glfw-input.c b/ffi/glfw-input.c index 252631a..ab99bdd 100644 --- a/ffi/glfw-input.c +++ b/ffi/glfw-input.c @@ -16,3 +16,11 @@ void setFramebufferSizeCallback(GLFWwindow* window) { glfwSetFramebufferSizeCallback(window, framebufferSizeCallback); } +void charCallback(GLFWwindow* window, unsigned int codepoint) { + mltonCharCallback(codepoint); +} + +void setCharCallback(GLFWwindow* window) { + glfwSetCharCallback(window, charCallback); +} + diff --git a/ffi/glfw-input.sml b/ffi/glfw-input.sml index 424c982..4e73e9d 100644 --- a/ffi/glfw-input.sml +++ b/ffi/glfw-input.sml @@ -19,4 +19,9 @@ struct _export "mltonFramebufferSizeCallback" public : (int * int -> unit) -> unit; val setFramebufferSizeCallback = _import "setFramebufferSizeCallback" public : window -> unit; + + val exportCharCallback = + _export "mltonCharCallback" public : (Word32.word -> unit) -> unit; + val setCharCallback = + _import "setCharCallback" public : window -> unit; end diff --git a/shell/shell.sml b/shell/shell.sml index 4526329..a38d025 100644 --- a/shell/shell.sml +++ b/shell/shell.sml @@ -6,11 +6,23 @@ struct fun frameBufferSizeCallback inputMailbox (width, height) = Mailbox.send (inputMailbox, RESIZE_EVENT (width, height)) + fun charCallback word = + let + val word = Word32.toInt word + val chr = Char.chr word + val s = Char.toString chr ^ "\n" + in + print s + end + fun registerCallbacks (inputMailbox, window) = let val resizeCallback = frameBufferSizeCallback inputMailbox val () = Input.exportFramebufferSizeCallback resizeCallback val () = Input.setFramebufferSizeCallback window + + val () = Input.exportCharCallback charCallback + val () = Input.setCharCallback window in () end diff --git a/shf b/shf index 5551ffc..b5ef7eb 100755 Binary files a/shf and b/shf differ