#include "wasm.h"
+extern wasm_instance_t* wasm_instance;
+extern wasm_module_t* wasm_module;
extern wasm_memory_t* wasm_memory;
+extern wasm_extern_t* wasm_extern_lookup_by_name(wasm_module_t* module, wasm_instance_t* instance, const char* name);
typedef struct WasmValkindBuffer {
unsigned int count;
glfwCreateStandardCursor :: (shape: i32) -> GLFWcursor_p ---
glfwDestroyCursor :: (cursor: GLFWcursor_p) -> void ---
glfwSetCursor :: (window: GLFWwindow_p, cursor: GLFWcursor_p) -> void ---
- // glfwSetKeyCallback
+ glfwSetKeyCallback :: (window: GLFWwindow_p, export_name: str) -> void ---
// glfwSetCharCallback
// glfwSetCharModsCallback
// glfwSetMouseButtonCallback
return NULL;
}
-// glfwGetInputMode :: (window: GLFWwindow_p, mode: i32) -> i32 ---
-// glfwSetInputMode :: (window: GLFWwindow_p, mode, value: i32) -> void ---
-// glfwRawMouseMotionSupported :: () -> i32 ---
ONYX_DEF(glfwGetInputMode, (LONG, INT), (INT)) {
GLFWwindow *window = (GLFWwindow *) params->data[0].of.i64;
results->data[0] = WASM_I32_VAL(glfwGetInputMode(window, params->data[1].of.i32));
return NULL;
}
-// // glfwSetKeyCallback
+wasm_func_t* __key_callback_func;
+static void __glfw_key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) {
+ wasm_val_t args[] = { WASM_I64_VAL((unsigned long) window), WASM_I32_VAL(key), WASM_I32_VAL(scancode), WASM_I32_VAL(action), WASM_I32_VAL(mods) };
+ wasm_val_vec_t args_array = WASM_ARRAY_VEC(args);
+ wasm_val_vec_t results;
+
+ wasm_func_call(__key_callback_func, &args_array, &results);
+}
+
+ONYX_DEF(glfwSetKeyCallback, (LONG, PTR, INT), ()) {
+ GLFWwindow *window = (GLFWwindow *) params->data[0].of.i64;
+
+ char name[512];
+ strncpy(name, ONYX_PTR(params->data[1].of.i32), params->data[2].of.i32);
+ name[params->data[2].of.i32] = '\0';
+
+ __key_callback_func = wasm_extern_as_func(wasm_extern_lookup_by_name(wasm_module, wasm_instance, name));
+
+ glfwSetKeyCallback(window, __glfw_key_callback);
+ return NULL;
+}
+
// // glfwSetCharCallback
// // glfwSetCharModsCallback
// // glfwSetMouseButtonCallback
ONYX_FUNC(glfwSetMonitorUserPointer)
ONYX_FUNC(glfwGetMonitorUserPointer)
+ ONYX_FUNC(glfwSetKeyCallback)
// // glfwGetKeyName :: (key, scancode: i32) -> cstr ---
-// // glfwSetKeyCallback
// // glfwSetCharCallback
// // glfwSetCharModsCallback
// // glfwSetMouseButtonCallback
static wasm_engine_t* wasm_engine;
static wasm_store_t* wasm_store;
static wasm_extern_vec_t wasm_imports;
-static wasm_module_t* wasm_module;
+wasm_instance_t* wasm_instance;
+wasm_module_t* wasm_module;
wasm_memory_t* wasm_memory;
b32 wasm_name_equals(const wasm_name_t* name1, const wasm_name_t* name2) {
onyx_lookup_and_load_custom_libraries(wasm_bytes);
- wasm_instance_t* instance = NULL;
wasmer_features_t* features = NULL;
wasm_trap_t* run_trap = NULL;
wasm_trap_t* traps = NULL;
- instance = wasm_instance_new(wasm_store, wasm_module, &wasm_imports, &traps);
- if (!instance) goto error_handling;
+ wasm_instance = wasm_instance_new(wasm_store, wasm_module, &wasm_imports, &traps);
+ if (!wasm_instance) goto error_handling;
- wasm_extern_t* start_extern = wasm_extern_lookup_by_name(wasm_module, instance, "_start");
+ wasm_extern_t* start_extern = wasm_extern_lookup_by_name(wasm_module, wasm_instance, "_start");
wasm_func_t* start_func = wasm_extern_as_func(start_extern);
wasm_val_vec_t args;
bh_printf("%b\n", buf, len);
cleanup:
- if (instance) wasm_instance_delete(instance);
+ if (wasm_instance) wasm_instance_delete(wasm_instance);
if (wasm_module) wasm_module_delete(wasm_module);
if (wasm_store) wasm_store_delete(wasm_store);
if (wasm_engine) wasm_engine_delete(wasm_engine);