jow- / ucode

JavaScript-like language with optional templating
ISC License
87 stars 24 forks source link

A few minor fixes/improvements to ucode #150

Closed nbd168 closed 1 year ago

nbd168 commented 1 year ago

Fixes for minor things that I noticed during review

jow- commented 1 year ago

Looks mostly fine to me but NAK on lib: traverse module search path in reverse order - the intent is to process the search path left to right, like it's done virtually everywhere (C compiler include paths, $PATH, Lua's package.path, Perl's @INC etc.)

What about simply moving the initialization of the default search path elements after the first optarg parse loop? This will ensure that any -L added elements come first while still maintaining the order of both the user added and default group of paths.

Suggested change:

diff --git a/main.c b/main.c
index 3957483..3fe81af 100644
--- a/main.c
+++ b/main.c
@@ -90,7 +90,7 @@ print_usage(const char *app)
    "  Preload the given `library`, optionally aliased to `name`.\n\n"

    "-L pattern\n"
-   "  Append given `pattern` to default library search paths. If the pattern\n"
+   "  Prepend given `pattern` to default library search paths. If the pattern\n"
    "  contains no `*`, it is added twice, once with `/*.so` and once with\n"
    "  `/*.uc` appended to it.\n\n"

@@ -505,8 +505,6 @@ main(int argc, char **argv)
        .raw_mode = true
    };

-   uc_search_path_init(&config.module_search_path);
-
    app = appname(argv[0]);

    if (argc == 1) {
@@ -544,6 +542,9 @@ main(int argc, char **argv)
        }
    }

+   /* add default search paths */
+   uc_search_path_init(&config.module_search_path);
+
    optind = 1;

    uc_vm_init(&vm, &config);
diff --git a/tests/cram/test_basic.t b/tests/cram/test_basic.t
index d7f78a3..798436e 100644
--- a/tests/cram/test_basic.t
+++ b/tests/cram/test_basic.t
@@ -61,7 +61,7 @@ check that ucode provides exepected help:
     Preload the given `library`, optionally aliased to `name`.

   -L pattern
-    Append given `pattern` to default library search paths. If the pattern
+    Prepend given `pattern` to default library search paths. If the pattern
     contains no `*`, it is added twice, once with `/*.so` and once with
     `/*.uc` appended to it.
jow- commented 1 year ago

Merged, thanks!