Using Nasal functions: Difference between revisions

Jump to navigation Jump to search
m
m (obviously, it's sorta "good" for the wiki that the forum is being maintained ;-))
Line 29: Line 29:
This will first call the inner hello() function, and afterwards the outer function. Note how only the outer function call has a terminating semicolon.
This will first call the inner hello() function, and afterwards the outer function. Note how only the outer function call has a terminating semicolon.


You may be wondering what's happening here by calling the hello() function this way, in a nested fashion. The truth is, functions don't always have empty parentheses - the parentheses are there to pass function arguments (parameters) to the function:
You may be wondering what's happening here by calling the hello() function this way, in a nested fashion.  
So called 'void' functions that don't return any values, will implicitly return '''nil''' to the caller() - so the inner hello() call would return nil to the outer hello() call, which is equivalent to calling '''hello(nil)'''.
 
The truth is, functions don't always have empty parentheses - the parentheses are there to pass function arguments (parameters) to the function:


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
hello( "FlightGear" );
hello( "FlightGear" );
</syntaxhighlight>
</syntaxhighlight>


This passes a single function argument to the hello function. In our previous example, we simply used the return value of the first (inner) function call as the argument of the outer (second) call.
This passes a single function argument to the hello function. In our previous example, we simply used the return value of the first (inner) function call as the argument of the outer (second) call.

Navigation menu