JS globbing; remove glob b/c windows; pregame script hooks
This commit is contained in:
@@ -79,10 +79,10 @@ JSValue str2js(const char *c) {
|
||||
return JS_NewString(js, c);
|
||||
}
|
||||
|
||||
JSValue strarr2js(const char **c, int len)
|
||||
JSValue strarr2js(const char **c)
|
||||
{
|
||||
JSValue arr = JS_NewArray(js);
|
||||
for (int i = 0; i < len; i++)
|
||||
for (int i = 0; i < arrlen(c); i++)
|
||||
JS_SetPropertyUint32(js, arr, i, JS_NewString(js, c[i]));
|
||||
|
||||
return arr;
|
||||
@@ -421,19 +421,6 @@ JSValue duk_nuke(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
|
||||
#endif
|
||||
|
||||
JSValue duk_win_make(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
/*
|
||||
const char *title = JS_ToCString(js, argv[0]);
|
||||
int w = js2int(argv[1]);
|
||||
int h = js2int(argv[2]);
|
||||
struct window *win = MakeSDLWindow(title, w, h, 0);
|
||||
JS_FreeCString(js, title);
|
||||
|
||||
return JS_NewInt64(js, win->id);
|
||||
*/
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_spline_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
static_assert(sizeof(tsReal) * 2 == sizeof(cpVect));
|
||||
|
||||
@@ -575,25 +562,6 @@ int file_exists(char *path) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
static int duk2path(const char *path, const struct stat *sb, int typeflag) {
|
||||
if (typeflag == FTW_F) {
|
||||
char *ext = strrchr(path, '.');
|
||||
if (ext && !strcmp(ext, dukext))
|
||||
JS_SetPropertyUint32(js, dukarr, dukidx++, JS_NewString(js, &path[2]));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
JSValue dukext2paths(char *ext) {
|
||||
char *paths = NULL;
|
||||
|
||||
fill_extensions(paths, ".", ext);
|
||||
// return dukarr;
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2int(argv[0]);
|
||||
const char *str = NULL;
|
||||
@@ -865,8 +833,7 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
break;
|
||||
|
||||
case 66:
|
||||
str = JS_ToCString(js, argv[1]);
|
||||
ret = dukext2paths(str);
|
||||
ret = strarr2js(ls(","));
|
||||
break;
|
||||
|
||||
case 67:
|
||||
@@ -1122,6 +1089,11 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
case 133:
|
||||
ret = JS_NewFloat64(js, appTime);
|
||||
break;
|
||||
|
||||
case 134:
|
||||
str = JS_ToCString(js,argv[1]);
|
||||
app_name(str);
|
||||
break;
|
||||
}
|
||||
|
||||
if (str)
|
||||
@@ -1687,7 +1659,6 @@ void ffi_load() {
|
||||
DUK_FUNC(q_body, 2)
|
||||
|
||||
DUK_FUNC(sys_cmd, 1)
|
||||
DUK_FUNC(win_make, 3)
|
||||
|
||||
DUK_FUNC(make_sprite, 3)
|
||||
DUK_FUNC(make_anim2d, 3)
|
||||
|
||||
@@ -109,6 +109,29 @@ void fill_extensions(char *paths, const char *path, const char *ext) {
|
||||
ext_paths = paths;
|
||||
ftw(".", ext_check, 10);
|
||||
}
|
||||
|
||||
static char **ls_paths = NULL;
|
||||
|
||||
static int ls_ftw(const char *path, const struct stat *sb, int typeflag)
|
||||
{
|
||||
if (typeflag == FTW_F && strlen(path) > 2)
|
||||
arrpush(ls_paths, strdup(&path[2]));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char **ls(char *path)
|
||||
{
|
||||
if (ls_paths) {
|
||||
for (int i = 0; i < arrlen(ls_paths); i++)
|
||||
free(ls_paths[i]);
|
||||
|
||||
arrfree(ls_paths);
|
||||
}
|
||||
ftw(".", ls_ftw, 10);
|
||||
return ls_paths;
|
||||
}
|
||||
|
||||
#else
|
||||
void fill_extensions(char *paths, const char *path, const char *ext)
|
||||
{};
|
||||
@@ -140,12 +163,6 @@ char *make_path(const char *file) {
|
||||
return pathbuf;
|
||||
}
|
||||
|
||||
char *strdup(const char *s) {
|
||||
char *new = malloc(sizeof(char) * (strlen(s) + 1));
|
||||
strcpy(new, s);
|
||||
return new;
|
||||
}
|
||||
|
||||
unsigned char *slurp_file(const char *filename, size_t *size)
|
||||
{
|
||||
if (cdb_find(&game_cdb, filename, strlen(filename))) {
|
||||
@@ -181,6 +198,7 @@ char *slurp_text(const char *filename, size_t *size)
|
||||
{
|
||||
size_t len;
|
||||
char *str = slurp_file(filename, &len);
|
||||
if (!str) return NULL;
|
||||
char *retstr = malloc(len+1);
|
||||
memcpy(retstr, str, len);
|
||||
retstr[len] = '\0';
|
||||
|
||||
@@ -13,8 +13,7 @@ char *str_replace_ext(const char *s, const char *newext);
|
||||
FILE *res_open(char *path, const char *tag);
|
||||
FILE *path_open(const char *tag, const char *fmt, ...);
|
||||
char *make_path(const char *file);
|
||||
|
||||
char *strdup(const char *s);
|
||||
char **ls(char *path);
|
||||
|
||||
unsigned char *slurp_file(const char *filename, size_t *size);
|
||||
char *slurp_text(const char *filename, size_t *size);
|
||||
|
||||
@@ -131,6 +131,7 @@ JSValue script_runfile(const char *file)
|
||||
{
|
||||
size_t len;
|
||||
const char *script = slurp_text(file, &len);
|
||||
if (!script) return JS_NULL;
|
||||
|
||||
JSValue obj = JS_Eval(js, script, len, file, JS_EVAL_FLAGS);
|
||||
js_print_exception(obj);
|
||||
|
||||
@@ -310,6 +310,11 @@ static sapp_desc start_desc = {
|
||||
.logger.func = sg_logging,
|
||||
};
|
||||
|
||||
void app_name(char *name)
|
||||
{
|
||||
start_desc.window_title = strdup(name);
|
||||
}
|
||||
|
||||
sapp_desc sokol_main(int argc, char **argv) {
|
||||
#ifndef NDEBUG
|
||||
#ifdef __linux__
|
||||
@@ -366,6 +371,8 @@ sapp_desc sokol_main(int argc, char **argv) {
|
||||
sound_init();
|
||||
input_init();
|
||||
|
||||
script_dofile("warmup.js");
|
||||
|
||||
start_desc.width = mainwin.width;
|
||||
start_desc.height = mainwin.height;
|
||||
start_desc.fullscreen = 0;
|
||||
|
||||
@@ -12,6 +12,7 @@ void set_timescale(float val);
|
||||
void print_stacktrace();
|
||||
|
||||
const char *engine_info();
|
||||
void app_name(char *name);
|
||||
|
||||
int frame_fps();
|
||||
double get_timescale();
|
||||
|
||||
Reference in New Issue
Block a user