mirror of
https://github.com/janet-lang/janet
synced 2025-04-28 05:33:18 +00:00
Address #211
Scripts run from the command line will automatically call a main function if it exists.
This commit is contained in:
parent
1fa7e73c58
commit
4de6c2ad61
@ -2222,8 +2222,12 @@
|
|||||||
(do
|
(do
|
||||||
(set *no-file* false)
|
(set *no-file* false)
|
||||||
(def env (make-env))
|
(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)
|
(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))))
|
(set i lenargs))))
|
||||||
|
|
||||||
(when (and (not *compile-only*) (or *should-repl* *no-file*))
|
(when (and (not *compile-only*) (or *should-repl* *no-file*))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user