f++ (scripting language)
functionstein jack jumper mascot

Nift has its own in-built scripting language f++, also nicknamed FUNCTIONSTEIN or FNSTEIN.

[contents]

Contents

f++ interpreter

Nift has an f++ interpreter that you can start with either nsm interp or nift interp (it is the default language for the interpeter mode). 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.

f++ shell

Nift has an f++ shell, also nicknamed FLASHELL, that you can start with either nsm sh or nift sh (it is the default language for the shell mode). 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 f++ scripts

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

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

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

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

If you want to run a normal file, eg. script.f, 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.

Automatic shell startup

On Unix based platforms (eg. probably all posix compliant Linux distributions, OSX, FreeBSD, Gentoo etc.), you can create an application launcher with x-terminal-emulator -e nift sh or gnome-terminal -- nift sh as the short-cut command, which will open a terminal session running FLASHELL and close upon exit.

From gnome-session-flashback I am able to create an application launcher from the gui by doing alt and right click in some free space on the top or bottom panel and selecting Add to Panel.... Alternatively create a file titled something like Terminal.desktop below and give exec permissions (calling the application Terminal gives a more native feel as it is going to be hijacked and renamed otherwise):

#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=true
Exec=x-terminal-emulator -e nift sh
Name=Terminal
Comment=flashell shortcut
Icon=<path-to-icon>

I often find it easier to just use the properties of the file through the gui to acccess the filesystem for linking to the icon file, typically from the desktop. Below is an icon people might like to use with their short-cut(s):

flash icon

If you prefer a more native feel without the icon being hijacked, the default icon used for gnome-terminal on gnome-session-flashback, at least on Ubuntu, is below:

gnome-terminal icon

and the default icon, or at least one similar to it, used for cmd.exe on Windows 10 is below:

Windows cmd.exe icon

You can start a session of eg. bash shell by simply typing bash from FLASHELL, which will also do lolcat output through bash if you have lolcat activated (which actually quite surprises me), however if you start another Nift shell or interpreter with lolcat activated the prompt line including user input stays invisible until you hit enter (just type exit if you accidentally do this).

On Windows one approach is to create a shortcut to cmd.exe to the command that is executed when the shortcut is opened and add /k nift sh to the end of the target under properties for the shortcut (or the powershell executeable if you would prefer adding -Command nift sh to the end of the target under properties for the duplicated powershell shortcut).

f++ from n++

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

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

Nift functions

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

funcName{options}(params)

Examples

There are some basic solutions to Project Euler problems available here.

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]);

The following script uses more ExprTk than above and runs faster:

#!/usr/bin/env nift
string params = "file0.txt";
int i;

exprtk
{
	for(i:=1; i<100000; i+=1) 
	{
	    params += ', file' + nsm_tostring('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. 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
}