From 09b1d46986561594b1a009f4a13b1ba8c0c148b0 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Thu, 8 Jun 2023 22:27:37 +0000 Subject: [PATCH] pinball --- source/engine/ffi.c | 7 ++++++- source/engine/script.c | 9 ++++++--- source/engine/script.h | 2 +- source/scripts/engine.js | 13 ++++++------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/source/engine/ffi.c b/source/engine/ffi.c index 8498a34..ee3c254 100644 --- a/source/engine/ffi.c +++ b/source/engine/ffi.c @@ -1033,13 +1033,18 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) return str2js(tex_get_path(js2sprite(argv[1])->tex)); case 117: str = JS_ToCString(js, argv[1]); - ret = JS_NewInt64(js, script_runfile(str)); + ret = script_runfile(str); break; case 118: str = JS_ToCString(js,argv[1]); return bb2js(text_bb(str, js2number(argv[2]), js2number(argv[3]), 1.0)); break; + + case 119: + str = JS_ToCString(js, argv[1]); + ret = JS_NewInt64(js, file_mod_secs(str)); + break; } if (str) diff --git a/source/engine/script.c b/source/engine/script.c index 83dc64c..36178ff 100644 --- a/source/engine/script.c +++ b/source/engine/script.c @@ -131,15 +131,18 @@ int script_dofile(const char *file) { return file_mod_secs(file); } -int script_runfile(const char *file) +JSValue script_runfile(const char *file) { const char *script = slurp_text(file); int bufsize = strlen(script)+50; char scriptbuffer[bufsize]; snprintf(scriptbuffer,bufsize, "(function(){%s})()", script); - script_run(scriptbuffer,file); + + JSValue obj = JS_Eval(js, script, strlen(script), file, JS_EVAL_FLAGS); + js_print_exception(obj); + free(script); - return file_mod_secs(file); + return obj; } /* env is an object in the scripting environment; diff --git a/source/engine/script.h b/source/engine/script.h index b837e3c..cb4d400 100644 --- a/source/engine/script.h +++ b/source/engine/script.h @@ -20,7 +20,7 @@ void script_startup(); void script_init(); void script_run(const char *script, const char *file); int script_dofile(const char *file); -int script_runfile(const char *file); +JSValue script_runfile(const char *file); void script_update(double dt); void script_draw(); diff --git a/source/scripts/engine.js b/source/scripts/engine.js index 6cc26e6..f8b8832 100644 --- a/source/scripts/engine.js +++ b/source/scripts/engine.js @@ -11,13 +11,17 @@ function load(file) { function run(file) { - var modtime = cmd(117,file); + var text = IO.slurp(file); + eval?.(`"use strict";${text}`); + return; + var modtime = cmd(119, file); if (modtime === 0) { Log.stack(); return false; } files[file] = modtime; + return cmd(117, file); } load("scripts/base.js"); @@ -280,11 +284,6 @@ GUI.defaults.debug_colors = { Object.values(GUI.defaults.debug_colors).forEach(function(v) { v.a = 100; }); - -function listbox(pos, item) { - pos.y += (item[1] - 20); -}; - var Yugine = { get dt() { return cmd(63); @@ -1195,7 +1194,7 @@ var Level = { this[x.varname] = x; } },this); - Log.warn("eval script"); + eval(this.script); if (typeof extern === 'object')