fn: function
[contents]

Contents

Syntax

The syntax for function definitions is:

f++:  
function{options}(name)
{
	//function code
}

n++:  
@function{options}(name)
{
	//function code
}

Description

The function function is for user-defined functions, it takes a single parameter specifying a function name and is followed by a block of code to be run whenever the function is called.

Note: Nift will skip to the first non-whitespace (ie. to the first character that is not a space, tab or newline) after a function definition and inject it to the output file where the definition started. If you want to prevent Nift from doing this put a '!' after the definition, eg.:

@function(f)
{
	# block
}!

Options

The following options are available for function calls:

option description
f++ function is in f++
n++ function is in n++
!const function is not constant
lambda function is a lambda
layer="l" define function at scope layer l
!o do not return output (option available at call time)
o return output (option available at call time)
pb parse function block at definition time
private function is private
scope+="s" function can be called from scope s
!s do not add scope when function is called (option available at call time)
s add scope when function is called [default] (option available at call time)
option description

f++ example

Examples of function being used with f++:

function(myFunc)
{
	console("hello, world!")
}

myFunc

function(myFunc)
{
	console("options: {", vjoin(options, "; "), "}")
	console("params: {", vjoin(params, "; "), "}")
}

myFunc{a, b, c}("hello", "world!")

n++ example

Example of function being used with n++:

@function(myFunc)
	@console("hello, world!")

@myFunc