From 9909d7d901e63d44fab5e96ca282c8c4244cd936 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Thu, 15 Jan 2026 12:19:41 +0100 Subject: [PATCH 1/2] feat(core): expose `km_core_state_options_update` to WASM Part-of: #13426 Test-bot: skip --- core/src/wasm.cpp | 17 +++++++++++++++++ web/src/engine/src/core-adapter/index.ts | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/src/wasm.cpp b/core/src/wasm.cpp index 1f0f383feed..d291dc87388 100644 --- a/core/src/wasm.cpp +++ b/core/src/wasm.cpp @@ -340,6 +340,21 @@ km_core_state_get_actions_wasm(km_core_state const *state) { return actions_wasm; } +int +km_core_state_options_update_wasm( + km_core_state const *state, + const std::vector& new_options +) { + km_core_option_item* options_c = new km_core_option_item[new_options.size() + 1]; + for (size_t i = 0; i < new_options.size(); ++i) { + options_c[i].key = new_options[i].key.c_str(); + options_c[i].value = new_options[i].value.c_str(); + options_c[i].scope = new_options[i].scope; + } + options_c[new_options.size()] = {nullptr, nullptr, 0}; + return km_core_state_options_update(const_cast(state), options_c); +} + const CoreReturn* km_core_context_get_wasm( km_core_context const* context @@ -484,6 +499,8 @@ EMSCRIPTEN_BINDINGS(core_interface) { em::function("state_get_actions(state)", &km_core_state_get_actions_wasm, em::allow_raw_pointers()); + em::function("state_options_update(state, new_options)", &km_core_state_options_update_wasm, em::allow_raw_pointers()); + em::function("context_get(context)", &km_core_context_get_wasm, em::allow_raw_pointers()); em::function("context_set(context, context_items)", &km_core_context_set_wasm, em::allow_raw_pointers()); } diff --git a/web/src/engine/src/core-adapter/index.ts b/web/src/engine/src/core-adapter/index.ts index 9052d97a9d0..f5a4ff2c785 100644 --- a/web/src/engine/src/core-adapter/index.ts +++ b/web/src/engine/src/core-adapter/index.ts @@ -1,3 +1,3 @@ export { KM_Core, KM_CORE_STATUS, KM_CORE_OPTION_SCOPE, KM_CORE_KMX_ENV, KM_CORE_CT } from './KM_Core.js'; -import { type km_core_keyboard, type km_core_state, type km_core_context, type km_core_context_item, type km_core_context_items } from './import/core/keymancore.js'; -export { km_core_keyboard, km_core_state, km_core_context, km_core_context_item, km_core_context_items }; +import { type km_core_keyboard, type km_core_state, type km_core_context, type km_core_context_item, type km_core_context_items, type km_core_option_item } from './import/core/keymancore.js'; +export { km_core_keyboard, km_core_state, km_core_context, km_core_context_item, km_core_context_items, km_core_option_item }; From 83dca0f7791b06bc14565a6dfdd4b070d5920d5a Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Mon, 19 Jan 2026 16:28:52 +0100 Subject: [PATCH 2/2] feat(core): address code review comments Test-bot: skip --- core/src/wasm.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/wasm.cpp b/core/src/wasm.cpp index d291dc87388..6289bf35f92 100644 --- a/core/src/wasm.cpp +++ b/core/src/wasm.cpp @@ -351,8 +351,10 @@ km_core_state_options_update_wasm( options_c[i].value = new_options[i].value.c_str(); options_c[i].scope = new_options[i].scope; } - options_c[new_options.size()] = {nullptr, nullptr, 0}; - return km_core_state_options_update(const_cast(state), options_c); + options_c[new_options.size()] = KM_CORE_OPTIONS_END; + km_core_status status = km_core_state_options_update(const_cast(state), options_c); + delete[] options_c; + return status; } const CoreReturn*