1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-24 06:03:17 +00:00
Scripts run from the command line will automatically
call a main function if it exists.
This commit is contained in:
Calvin Rose 2019-12-06 19:14:12 -06:00
parent 1fa7e73c58
commit 4de6c2ad61

View File

@ -2222,8 +2222,12 @@
(do
(set *no-file* false)
(def env (make-env))
(put env :args (array/slice args i))
(def subargs (array/slice args i))
(put env :args subargs)
(dofile arg :prefix "" :exit *exit-on-error* :evaluator evaluator :env env)
(if-let [main (get (in env 'main) :value)]
(let [thunk (compile [main ;(tuple/slice args i)] env arg)]
(if (function? thunk) (thunk) (error (thunk :error)))))
(set i lenargs))))
(when (and (not *compile-only*) (or *should-repl* *no-file*))