documentation update

This commit is contained in:
2025-02-04 22:18:46 -06:00
parent b41f00458b
commit f53e46ee9e
106 changed files with 780 additions and 2984 deletions

View File

@@ -5855,7 +5855,9 @@ struct globdata {
JSContext *js;
JSValue arr;
char **globs;
char *glob;
int idx;
int recurse;
};
int globfs_cb(struct globdata *data, char *dir, char *file)
@@ -5893,12 +5895,11 @@ int globfs_cb(struct globdata *data, char *dir, char *file)
return 1;
}
JSC_SSCALL(io_match,
if (wildmatch(str, str2, WM_PATHNAME | WM_PERIOD | WM_WILDSTAR) == WM_MATCH)
ret = JS_NewBool(js,1);
else
ret = JS_NewBool(js, 0);
ret = JS_NewBool(js,0);
)
JSC_CCALL(io_globfs,
@@ -5919,7 +5920,63 @@ JSC_CCALL(io_globfs,
PHYSFS_enumerate("", globfs_cb, &data);
return data.arr;
for (int i = 0; i < globs_len; i++)
JS_FreeCString(js,globs[i]);
ret = data.arr;
)
static int enumerate_cb(void *udata, const char *dir, const char *fname)
{
struct globdata *data = (struct globdata*)udata;
char *path;
int needfree = 0;
if (dir[0] == 0) path = (char*)fname;
else {
path = malloc(strlen(dir) + strlen(fname) + 2);
sprintf(path, "%s/%s", dir, fname);
needfree = 1;
}
PHYSFS_Stat st;
if (!PHYSFS_stat(path, &st)) { /* Could not stat, skip */
if (needfree) free(path);
return 1;
}
/* If it's a directory and we're recursing, enumerate it further. */
if (st.filetype == PHYSFS_FILETYPE_DIRECTORY && data->recurse)
PHYSFS_enumerate(path, enumerate_cb, data);
/* Add this item (file or directory) to the JS array. */
JS_SetPropertyUint32(data->js, data->arr, data->idx++, JS_NewString(data->js, path));
if (needfree) free(path);
return 1; /* continue enumerating */
}
JSC_SCALL(io_enumerate,
/* First argument: str (directory name) */
/* Second argument: boolean => recurse or not */
ret = JS_NewArray(js);
struct globdata data;
data.js = js;
data.arr = ret;
data.idx = 0;
data.glob = NULL; /* not used here */
data.globs = NULL; /* not used here */
data.recurse = 0;
if (!JS_IsUndefined(argv[1])) /* parse second arg if provided */
data.recurse = JS_ToBool(js, argv[1]);
/* Enumerate the directory given by 'str'. */
PHYSFS_enumerate(str, enumerate_cb, &data);
/* Return the JS array we filled. */
ret = data.arr;
)
JSC_CCALL(io_basedir, return JS_NewString(js,PHYSFS_getBaseDir()))
@@ -5966,6 +6023,7 @@ static const JSCFunctionListEntry js_io_funcs[] = {
MIST_FUNC_DEF(io, realdir, 1),
MIST_FUNC_DEF(io, open, 1),
MIST_FUNC_DEF(io, searchpath, 0),
MIST_FUNC_DEF(io, enumerate, 2),
};
JSC_CCALL(file_close,
@@ -7499,8 +7557,6 @@ JSValue js_imgui_use(JSContext *js);
#define MISTLINE(NAME) (ModuleEntry){#NAME, js_##NAME##_use}
void ffi_load(JSContext *js, int argc, char **argv) {
JSValue DOC = JS_NewSymbol(js, "+documentation+", 0);
arrput(module_registry, MISTLINE(io));
arrput(module_registry, MISTLINE(os));
arrput(module_registry, MISTLINE(input));
@@ -7691,7 +7747,6 @@ void ffi_load(JSContext *js, int argc, char **argv) {
JS_SetPropertyStr(js,prosp, "version", JS_NewString(js,PROSPERON_VERSION));
JS_SetPropertyStr(js,prosp,"revision",JS_NewString(js,PROSPERON_COMMIT));
JS_SetPropertyStr(js,prosp,"engine_start", JS_NewCFunction(js,js_os_engine_start, "engine_start", 1));
JS_SetPropertyStr(js,prosp,"DOC", DOC);
JS_SetPropertyStr(js,globalThis,"prosperon", prosp);