From 0973e261507f9ec6ef3dad808e9ba14a264227cc Mon Sep 17 00:00:00 2001 From: Reuben Dunnington Date: Tue, 22 Aug 2023 13:44:04 -0700 Subject: [PATCH] expose oc_request_quit() to wasm runtime --- src/app/app.h | 3 ++- src/app/orca_app.c | 7 +++++++ src/runtime.c | 9 +++++++++ src/runtime.h | 3 ++- src/wasmbind/core_api.json | 6 +++++- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/app/app.h b/src/app/app.h index 297165a..dec985c 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -274,6 +274,8 @@ extern "C" } oc_event; + ORCA_API void oc_request_quit(void); + //NOTE: these APIs are not directly available to Orca apps #if !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA) //-------------------------------------------------------------------- @@ -285,7 +287,6 @@ extern "C" ORCA_API bool oc_should_quit(void); ORCA_API void oc_cancel_quit(void); - ORCA_API void oc_request_quit(void); ORCA_API void oc_set_cursor(oc_mouse_cursor cursor); diff --git a/src/app/orca_app.c b/src/app/orca_app.c index fd349f0..ae046d3 100644 --- a/src/app/orca_app.c +++ b/src/app/orca_app.c @@ -2,3 +2,10 @@ //This is used to pass raw events from the runtime ORCA_EXPORT oc_event oc_rawEvent; + +void ORCA_IMPORT(oc_request_quit_stub)(void); + +void oc_request_quit() +{ + oc_request_quit_stub(); +} diff --git a/src/runtime.c b/src/runtime.c index 3104420..5ee8118 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -796,6 +796,15 @@ i32 orca_runloop(void* user) oc_arena_clear(oc_scratch()); } + if(exports[OC_EXPORT_TERMINATE]) + { + M3Result res = m3_Call(exports[OC_EXPORT_TERMINATE], 0, 0); + if(res) + { + ORCA_WASM3_ABORT(app->runtime.m3Runtime, res, "Runtime error"); + } + } + return (0); } diff --git a/src/runtime.h b/src/runtime.h index aa7bcec..92302e4 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -26,7 +26,8 @@ X(OC_EXPORT_KEY_UP, "oc_on_key_up", "", "i") \ X(OC_EXPORT_FRAME_REFRESH, "oc_on_frame_refresh", "", "") \ X(OC_EXPORT_FRAME_RESIZE, "oc_on_resize", "", "ii") \ - X(OC_EXPORT_RAW_EVENT, "oc_on_raw_event", "", "i") + X(OC_EXPORT_RAW_EVENT, "oc_on_raw_event", "", "i") \ + X(OC_EXPORT_TERMINATE, "oc_on_terminate", "", "") typedef enum { diff --git a/src/wasmbind/core_api.json b/src/wasmbind/core_api.json index 1e4a0ea..2286851 100644 --- a/src/wasmbind/core_api.json +++ b/src/wasmbind/core_api.json @@ -62,6 +62,10 @@ "name": "oc_get_host_platform", "cname": "oc_get_host_platform", "ret": {"name": "int", "tag": "i"}, - "args": [] +}, +{ + "name": "oc_request_quit_stub", + "cname": "oc_request_quit", + "ret": {"name": "void", "tag": "v"}, } ]