From c27817b73abdae863a194da4d50a10fd0df3b75f Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Sun, 23 Feb 2025 16:07:09 -0600 Subject: [PATCH] dmon now only watches top level directory; user must call dmon.watch and supply a dmon watch function --- scripts/modules/loop.js | 5 +++++ source/jsffi.c | 5 ----- source/qjs_dmon.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/modules/loop.js b/scripts/modules/loop.js index 6fadd89c..d50cfe7d 100644 --- a/scripts/modules/loop.js +++ b/scripts/modules/loop.js @@ -14,7 +14,12 @@ var frame_t = 0 var fpses = [] var timescale = 1 +var dmon = use('dmon') + function step() { + if (dmon) + dmon.poll(prosperon.dmon) + var now = os.now() var dt = now - last_frame_time if (dt < waittime) os.sleep(waittime - dt) diff --git a/source/jsffi.c b/source/jsffi.c index 98abbdfa..1f61c158 100644 --- a/source/jsffi.c +++ b/source/jsffi.c @@ -417,11 +417,6 @@ static BufferCheckResult get_or_extend_buffer( #include #endif -#if (defined(_WIN32) || defined(__WIN32__)) -#include -#define mkdir(x,y) _mkdir(x) -#endif - struct lrtb { float l; float r; diff --git a/source/qjs_dmon.c b/source/qjs_dmon.c index 5adaf9fa..a45d3c78 100644 --- a/source/qjs_dmon.c +++ b/source/qjs_dmon.c @@ -71,9 +71,8 @@ JSValue js_dmon_watch(JSContext *js, JSValue self, int argc, JSValue *argv) { if (watched.id) return JS_ThrowReferenceError(js, "Already watching a directory."); - - const char *dir = JS_ToCString(js,argv[0]); - watched = dmon_watch(dir,watch_cb, DMON_WATCHFLAGS_RECURSIVE, NULL); + + watched = dmon_watch(".", watch_cb, DMON_WATCHFLAGS_RECURSIVE, NULL); return JS_UNDEFINED; } @@ -90,6 +89,7 @@ JSValue js_dmon_unwatch(JSContext *js, JSValue self, int argc, JSValue *argv) JSValue js_dmon_poll(JSContext *js, JSValueConst this_val, int argc, JSValueConst *argv) { FileEvent event; while (dequeue_event(&event)) { + if (!JS_IsFunction(js, argv[0])) continue; JSValue jsevent = JS_NewObject(js); JSValue action; switch(event.action) { @@ -116,7 +116,7 @@ JSValue js_dmon_poll(JSContext *js, JSValueConst this_val, int argc, JSValueCons } static const JSCFunctionListEntry js_dmon_funcs[] = { - JS_CFUNC_DEF("watch", 1, js_dmon_watch), + JS_CFUNC_DEF("watch", 0, js_dmon_watch), JS_CFUNC_DEF("unwatch", 0, js_dmon_unwatch), JS_CFUNC_DEF("poll", 1, js_dmon_poll) };