This commit is contained in:
John Alanbrook 2023-06-08 22:27:37 +00:00
parent 0c6929893b
commit 09b1d46986
4 changed files with 19 additions and 12 deletions

View file

@ -1033,13 +1033,18 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
return str2js(tex_get_path(js2sprite(argv[1])->tex)); return str2js(tex_get_path(js2sprite(argv[1])->tex));
case 117: case 117:
str = JS_ToCString(js, argv[1]); str = JS_ToCString(js, argv[1]);
ret = JS_NewInt64(js, script_runfile(str)); ret = script_runfile(str);
break; break;
case 118: case 118:
str = JS_ToCString(js,argv[1]); str = JS_ToCString(js,argv[1]);
return bb2js(text_bb(str, js2number(argv[2]), js2number(argv[3]), 1.0)); return bb2js(text_bb(str, js2number(argv[2]), js2number(argv[3]), 1.0));
break; break;
case 119:
str = JS_ToCString(js, argv[1]);
ret = JS_NewInt64(js, file_mod_secs(str));
break;
} }
if (str) if (str)

View file

@ -131,15 +131,18 @@ int script_dofile(const char *file) {
return file_mod_secs(file); return file_mod_secs(file);
} }
int script_runfile(const char *file) JSValue script_runfile(const char *file)
{ {
const char *script = slurp_text(file); const char *script = slurp_text(file);
int bufsize = strlen(script)+50; int bufsize = strlen(script)+50;
char scriptbuffer[bufsize]; char scriptbuffer[bufsize];
snprintf(scriptbuffer,bufsize, "(function(){%s})()", script); 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); free(script);
return file_mod_secs(file); return obj;
} }
/* env is an object in the scripting environment; /* env is an object in the scripting environment;

View file

@ -20,7 +20,7 @@ void script_startup();
void script_init(); void script_init();
void script_run(const char *script, const char *file); void script_run(const char *script, const char *file);
int script_dofile(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_update(double dt);
void script_draw(); void script_draw();

View file

@ -11,13 +11,17 @@ function load(file) {
function run(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) { if (modtime === 0) {
Log.stack(); Log.stack();
return false; return false;
} }
files[file] = modtime; files[file] = modtime;
return cmd(117, file);
} }
load("scripts/base.js"); load("scripts/base.js");
@ -280,11 +284,6 @@ GUI.defaults.debug_colors = {
Object.values(GUI.defaults.debug_colors).forEach(function(v) { v.a = 100; }); Object.values(GUI.defaults.debug_colors).forEach(function(v) { v.a = 100; });
function listbox(pos, item) {
pos.y += (item[1] - 20);
};
var Yugine = { var Yugine = {
get dt() { get dt() {
return cmd(63); return cmd(63);
@ -1195,7 +1194,7 @@ var Level = {
this[x.varname] = x; this[x.varname] = x;
} }
},this); },this);
Log.warn("eval script");
eval(this.script); eval(this.script);
if (typeof extern === 'object') if (typeof extern === 'object')