Core Function MKFunc

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> MKFunc ( <params>, <body> ) </pre> === Description === Create a user defined function to be called from a variable. === params=== A string that will be the functions pa...")
 
m (1 revision)
 
(5 intermediate revisions by one user not shown)
Line 17: Line 17:
 
=== Return Value ===
 
=== Return Value ===
  
Acts like a regular function call.
+
Success: A function variable that can be called later when needed.
 +
 
 +
Failure: Returns null
  
 
=== Remarks ===
 
=== Remarks ===
Line 47: Line 49:
 
my $Func =  Function( $a, $b ){ println("Value is: " . ($a + $b)); };
 
my $Func =  Function( $a, $b ){ println("Value is: " . ($a + $b)); };
 
CallFunc($Func, array(10, 20));
 
CallFunc($Func, array(10, 20));
 +
</syntaxhighlight>
 +
 +
Same as above but this time calling directly instead of using CallFunc
 +
 +
<syntaxhighlight lang="sputnik">
 +
my $Func =  Function( $a, $b ){ println("Value is: " . ($a + $b)); };
 +
$Func(10, 20);
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 12:37, 14 June 2015

MKFunc ( <params>, <body> )

Contents

Description

Create a user defined function to be called from a variable.

params

A string that will be the functions parameters.

body

A string that will be the functions body.

Return Value

Success: A function variable that can be called later when needed.

Failure: Returns null

Remarks

The body does not need a { } block it already includes one in the build.

Example

Simple hello world with no params

my $Func = MKFunc('', 'println("Hello World");');
CallFunc($Func);

One with params

my $Func = MKFunc('$a, $b', 'println("Value is: " . ($a + $b));');
CallFunc($Func, array(10, 20));

Same as above but this time using the function(){} statement instead of MKFunc

my $Func = Function(){ println("Hello World");};
CallFunc($Func);
 
my $Func =  Function( $a, $b ){ println("Value is: " . ($a + $b)); };
CallFunc($Func, array(10, 20));

Same as above but this time calling directly instead of using CallFunc

my $Func =  Function( $a, $b ){ println("Value is: " . ($a + $b)); };
$Func(10, 20);
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox