pinball
This commit is contained in:
parent
0c6929893b
commit
09b1d46986
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue