- Run a script
- Load the script from a file and run it
- Using command line arguments
- Passing a load-path
foo> java -jar venice-1.12.34.jar -script "(+ 1 1)"
=> 2
File "script.venice":
(do
(defn circle-area [radius]
(* math/PI radius radius))
(println (circle-area 2.5)))
run:
foo> java -jar venice-1.12.34.jar -file script.venice
=> 19.634954084936208
Venice passes the command line args as ARGV vector.
File "script.venice":
(+ 1 (long (first *ARGV*)))
run:
foo> java -jar venice-1.12.34.jar -file script.venice 3
=> 4
Note: the command line args are only available when executing a script in the ways shown above. The command line args are not available in the REPL and for security reasons they are not available with embedding Venice in Java!
Venice scripts often uses the function load-file
to load a file with
Venice functions. load-file
loads the files by default from the current working
directory. The command line option "-loadpath" defines a set of semi-colon
separated paths files are searched for.
File "/users/foo/venice/test.venice":
(do
(defn circle-area [radius]
(* math/PI radius radius)))
File "/users/foo/venice/script.venice":
(do
(load-file "test.venice")
(println (circle-area 2.5))
Files:
/users/foo/venice
├── script.venice
├── libs
│ └── venice-1.12.34.jar
└── scripts
└── test.venice
Run:
foo> cd /users/foo/venice
foo> java -jar libs/venice-1.12.34.jar -file script.venice -loadpath "/users/foo/venice/scripts"
The script loads "test.venice" from "/users/foo/venice/scripts/test.venice".