mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-06-15 08:26:16 +08:00
The Emscripten wrapper exported only the eval family, leaving JS consumers with no way to snapshot or restore the singleton ChaiScript engine. The playground in chaiscript.github.io needs that to reset between runs without reloading the WASM module. Added handle-based wrappers that hide ChaiScript::State behind an int registry so JS callers don't have to manage embind object lifetimes, exported them as saveState/restoreState/releaseState, and added a native regression test that exercises capture, restore, and release through the same wrapper functions the WASM binding uses. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
27 lines
1.0 KiB
C++
27 lines
1.0 KiB
C++
// This file is distributed under the BSD License.
|
|
// See "license.txt" for details.
|
|
// Copyright 2019, Rob Loach (https://github.com/RobLoach/ChaiScript.js)
|
|
// Copyright 2009-2018, Jason Turner (jason@emptycrate.com)
|
|
// http://www.chaiscript.com
|
|
//
|
|
// Emscripten/WebAssembly wrapper for ChaiScript.
|
|
// Based on work by Rob Loach: https://github.com/RobLoach/ChaiScript.js
|
|
|
|
#include "chaiscript_eval.hpp"
|
|
|
|
#ifdef __EMSCRIPTEN__
|
|
#include <emscripten/bind.h>
|
|
|
|
EMSCRIPTEN_BINDINGS(chaiscript) {
|
|
emscripten::function("eval", &chaiscript_eval);
|
|
emscripten::function("evalString", &chaiscript_eval_string);
|
|
emscripten::function("evalBool", &chaiscript_eval_bool);
|
|
emscripten::function("evalInt", &chaiscript_eval_int);
|
|
emscripten::function("evalFloat", &chaiscript_eval_float);
|
|
emscripten::function("evalDouble", &chaiscript_eval_double);
|
|
emscripten::function("saveState", &chaiscript_save_state);
|
|
emscripten::function("restoreState", &chaiscript_restore_state);
|
|
emscripten::function("releaseState", &chaiscript_release_state);
|
|
}
|
|
#endif
|