Update jerryscript each frame.

This commit is contained in:
2026-06-06 10:30:22 -05:00
parent 5a08384ae1
commit 6f47543720
5 changed files with 40 additions and 21 deletions
+1
View File
@@ -78,6 +78,7 @@ errorret_t engineUpdate(void) {
errorChain(cutsceneUpdate());
sceneUpdate();
errorChain(assetUpdate());
errorChain(scriptUpdate());
if(inputPressed(INPUT_ACTION_RAGEQUIT)) ENGINE.running = false;
errorOk();
+21
View File
@@ -27,6 +27,27 @@ errorret_t scriptInit(void) {
errorOk();
}
errorret_t scriptUpdate() {
jerry_value_t ret = jerry_run_jobs();
if(jerry_value_is_exception(ret)) {
char_t buf[256];
jerry_value_t errVal = jerry_exception_value(ret, false);
jerry_value_t errStr = jerry_value_to_string(errVal);
jerry_size_t len = jerry_string_to_buffer(
errStr, JERRY_ENCODING_UTF8, (jerry_char_t *)buf, sizeof(buf) - 1
);
buf[len] = '\0';
jerry_value_free(errStr);
jerry_value_free(errVal);
jerry_value_free(ret);
errorThrow("Script error: %s", buf);
}
jerry_value_free(ret);
errorOk();
}
errorret_t scriptExecString(const char_t *source) {
assertNotNull(source, "Source cannot be NULL");
assertTrue(SCRIPT.initialized, "Script system not initialized");
+8
View File
@@ -22,6 +22,14 @@ extern script_t SCRIPT;
*/
errorret_t scriptInit(void);
/**
* Updates the script system, running any pending jobs. This should be called
* once per frame.
*
* @return Any error that occurred.
*/
errorret_t scriptUpdate(void);
/**
* Evaluates a JS source string in the global scope.
*