From a3a3e4c0dcce405c471af260303548a6b29418dd Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 27 Jul 2019 09:31:03 -0500 Subject: [PATCH] Add (dyn :executable). Also remove process/args. --- CHANGELOG.md | 2 ++ auxbin/jpm | 2 +- auxlib/cook.janet | 3 +-- src/mainclient/init.janet | 4 +--- src/mainclient/main.c | 5 ++++- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 543c709b..0b0f1ab9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. ## Unreleased - Add file associations on windows with default install. +- Add `(dyn :executable)` at top level to get what used to be + `(process/args 0)`. - Add `:linux` to platforms returned by `(os/which)`. - Update jpm to build standalone executables. Use `declare-executable` for this. - Add `use` macro. diff --git a/auxbin/jpm b/auxbin/jpm index 8e70eaa2..00f62d4e 100755 --- a/auxbin/jpm +++ b/auxbin/jpm @@ -83,7 +83,7 @@ Flags are: "clear-cache" cook/clear-cache "uninstall" uninstall}) -(def args (tuple/slice (dyn :args) 2)) +(def args (tuple/slice (dyn :args) 1)) (def len (length args)) (var i 0) diff --git a/auxlib/cook.janet b/auxlib/cook.janet index 10f9b6aa..e09ec03b 100644 --- a/auxlib/cook.janet +++ b/auxlib/cook.janet @@ -353,8 +353,7 @@ # Load entry environment and get main function. (def entry-env (dofile source)) (def main ((entry-env 'main) :value)) - # Get environments for every native module for the marshalling - # dictionary + # Create marshalling dictionary (def mdict (invert (env-lookup root-env))) # Build image (def image (marshal main mdict)) diff --git a/src/mainclient/init.janet b/src/mainclient/init.janet index 5956598f..72daac4e 100644 --- a/src/mainclient/init.janet +++ b/src/mainclient/init.janet @@ -1,7 +1,5 @@ # Copyright 2017-2019 (C) Calvin Rose -(def process/args "Deprecated. use '(dyn :args)' at script entry instead for process argument array." - (dyn :args)) (do (var *should-repl* false) @@ -66,7 +64,7 @@ (if h (h i) (do (print "unknown flag -" n) ((get handlers "h"))))) # Process arguments - (var i 1) + (var i 0) (def lenargs (length args)) (while (< i lenargs) (def arg (get args i)) diff --git a/src/mainclient/main.c b/src/mainclient/main.c index 81edebc0..baed5a79 100644 --- a/src/mainclient/main.c +++ b/src/mainclient/main.c @@ -61,10 +61,13 @@ int main(int argc, char **argv) { /* Create args tuple */ args = janet_array(argc); - for (i = 0; i < argc; i++) + for (i = 1; i < argc; i++) janet_array_push(args, janet_cstringv(argv[i])); janet_table_put(env, janet_ckeywordv("args"), janet_wrap_array(args)); + /* Save current executable path to (dyn :executable) */ + janet_table_put(env, janet_ckeywordv("executable"), janet_cstringv(argv[0])); + /* Run startup script */ status = janet_dobytes(env, janet_gen_init, janet_gen_init_size, "init.janet", NULL);