n++ (template language)
templatestein koala mascot

Nift has its own in-built template language n++, also nicknamed TEMPLATESTEIN.

[contents]

Contents

n++ interpreter

Nift has an n++ interpreter that you can start with either nsm interp -n++ or nift interp -n++. See the interactive REPL page for docs.

In the interpreter mode the prompt will just tell you which language you are using. If you would like the prompt to also display the present working directory (up to using half the width of the console) you can switch to the shell mode using nsm_mode("sh"). You can switch back again with nsm_mode("interp").

You can switch to one of the other languages available in Nift's interpreter using nsm_lang(langStr) where langStr is one of f++, n++, lua or exprtk.

n++ shell

Nift has an n++ shell that you can start with either nsm sh -n++ or nift sh -n++. See the interactive REPL page for docs.

In the shell mode the prompt will tell you which language you are using and the present working directory (up to using half the width of the console). If you would like the prompt to just display the language you can switch to the interpreter mode using nsm_mode("interp"). You can switch back again with nsm_mode("sh").

You can switch to one of the other languages available in Nift using nsm_lang(langStr) where langStr is one of f++, n++, lua or exprtk.

Running n++ scripts

If you have an n++ script saved in a file path/script-name.n you can run it with either of the following:

nsm run path/script-name.n
nift run path/script-name.n

If the script has a different extension, say .ext, you can run the script with either of the following:

nsm run -n++ path/script-name.ext
nift run -n++ path/script-name.ext

If you want to run a normal file, eg. script.n, as a script then use something typical like the following as a shebang:

#!/usr/bin/env nift

There's information about "run commands" scripts, eg. niftrc.f available on the REPL page.

n++ from f++

You can run n++ code from f++ using either of the following:

n++(/* single line of n++ code */)
n++
{
	// block of n++ code
}

Nift functions

All of Nift's hard-coded functions (including functions for defining variables, functions and structs) are available in your n++ code. The syntax for calling a function is as follows:

@funcName{options}(params)

Examples

The following script will create and delete 100k files on your machine:

#!/usr/bin/env nift
@string(params = "file0.txt");
 
@for(int i=1; i<100000; i+=1) 
    $`params += ', file$[i].txt'`;
 
@poke($[params]);
@rmv($[params]);

Note: do not leave the directory you are running the script from open on your machine, run it from a terminal/command prompt. The following bash script will do the same but much slower, feel free to provide a similar windows script in powershell or a batch file:

#!/usr/bin/env bash
COUNTER=0
while [  $COUNTER -lt 100000 ]; do
    let COUNTER=COUNTER+1 
 
    touch file${COUNTER}.txt
    rm file${COUNTER}.txt
done
{