Core Function Call
From Sputnik Wiki
(Difference between revisions)
m (1 revision) |
|||
(4 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
− | Call <function/array>, <expressions> | + | Call(<function/array>, <expressions>) |
</pre> | </pre> | ||
Line 28: | Line 28: | ||
The function can pass arguments to functions, also & pointer parameters are supported. | The function can pass arguments to functions, also & pointer parameters are supported. | ||
+ | |||
+ | Warning: The function NAME is taken as a string is only ever parsed ONCE so make sure you send a string that you know is not going to be changing such a literal string "myfunc" | ||
=== Example === | === Example === | ||
Line 38: | Line 40: | ||
println("Hello from test ($a, $b)"); | println("Hello from test ($a, $b)"); | ||
} | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Example of using the first param as an array to call stuff within classes etc | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | Class Testy | ||
+ | { | ||
+ | Function __Construct() | ||
+ | { | ||
+ | Call( array($this, "Test"), 10, 20); | ||
+ | } | ||
+ | |||
+ | Function Test($a, $b) | ||
+ | { | ||
+ | println("Hello from test ($a, $b)"); | ||
+ | } | ||
+ | }; | ||
+ | my $newTesty = new Testy(); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:37, 14 June 2015
Call(<function/array>, <expressions>)
Contents |
Description
Calls a function contained in a string parameter.
function
The name of the user function to call.
OR
A two element array to use as the call class and function name.
expressions
None, One or more arguments to send to the function.
Return Value
Acts like a regular function call.
Remarks
The function CAN be a built-in Sputnik function or a user defined one.
The function can pass arguments to functions, also & pointer parameters are supported.
Warning: The function NAME is taken as a string is only ever parsed ONCE so make sure you send a string that you know is not going to be changing such a literal string "myfunc"
Example
Call( "Test", 10, 20); Function Test($a, $b) { println("Hello from test ($a, $b)"); }
Example of using the first param as an array to call stuff within classes etc
Class Testy { Function __Construct() { Call( array($this, "Test"), 10, 20); } Function Test($a, $b) { println("Hello from test ($a, $b)"); } }; my $newTesty = new Testy();