Core Function MKFunc

From Sputnik Wiki
Revision as of 12:37, 14 June 2015 by UberFoX (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
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