Repository navigation
first_project
Niv supports both single-script projects and multi-scipts ones. This chapter will walk you through how to create and manage both.
Say we have this script we want to run:
// hello_world.niv
#MAIN |
print "Hello, Niv!\n"
#MAINThe simplest way to run it would be:
cargo run -- -f path/to/hello_world.niv
or
./niv -f path/to/hello_world.nivThe -f parameter is short for --file-list, which will be explained later.
This would run our script and print Hello, Niv! to the screen.
There are two ways to structure a mutlifile porject in Niv, the first being a simple file-list and the second being a project-file.
For explaining it better, we will use two demo files:
// helper.niv
#helper_func |
print "Hello from helper_func!\n"
#helper_func// main.niv
#MAIN |
helper_func
#MAINAs shown before, the simplest way to run a multi-script project is using a file-list: the files get loaded into the buffer according to the order the list was entered. So, the line
cargo run -- -f path/to/helper.niv path/to/main.niv
or
./niv -f path/to/helper.niv path/to/main.nivwould run the program as expected.
While a file-list is the most straightforward way to acheive this goal, it can get tidious to enter the entire list every time you want to run the project.
The solution to that would be a project-file like so:
# project.prj
helper.niv
main.niv
# or even another project file:
# ../libs/mathlib/mathlib.prj
that would be called like so:
cargo run -- -p path/to/project.prj
./niv -p path/to/project.prjA project file does exactly what a file-list does, only it's in a single neat file instead of having to expand on the "compiliation" line every time a new file is added.