Core Function CallArray
From Sputnik Wiki
(Difference between revisions)
(→function) |
m (4 revisions) |
||
| (11 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
<pre> | <pre> | ||
| − | CallArray <function>, <array> | + | CallArray(<function/array>, <array>) |
</pre> | </pre> | ||
| Line 13: | Line 13: | ||
OR | OR | ||
| − | A two element array to use as the call class and function name | + | A two element array to use as the call class and function name. |
=== array === | === array === | ||
| Line 28: | Line 28: | ||
This is similar to the Call() function but instead of sending arguments separated by , instead it sends a single array AS the arguments (The array will be resolved into individual arguments). | This is similar to the Call() function but instead of sending arguments separated by , instead it sends a single array AS the arguments (The array will be resolved into individual arguments). | ||
| + | |||
| + | 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 34: | Line 36: | ||
CallArray("Test", array("One", "Two", "Three")); | CallArray("Test", array("One", "Two", "Three")); | ||
| + | [Args("true")] // Allow the @args variable to be made (we will use it) | ||
Function Test() | Function Test() | ||
{ | { | ||
| Line 43: | Line 46: | ||
} | } | ||
} | } | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | Example of using first param as an array | ||
| + | |||
| + | <syntaxhighlight lang="sputnik"> | ||
| + | Class Testy | ||
| + | { | ||
| + | Function __Construct() | ||
| + | { | ||
| + | CallArray(array($this, "Test"), array("One", "Two", "Three")); | ||
| + | } | ||
| + | [Args("true")] // Allow the @args variable to be made (we will use it) | ||
| + | Function Test() | ||
| + | { | ||
| + | my $i = 0; | ||
| + | foreach( @args as my $item ) | ||
| + | { | ||
| + | println("ARG$i: $item"); | ||
| + | $i++; | ||
| + | } | ||
| + | } | ||
| + | }; | ||
| + | my $newTesty = new Testy(); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] | ||
Latest revision as of 12:37, 14 June 2015
CallArray(<function/array>, <array>)
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.
array
An array to send as the arguments 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.
This is similar to the Call() function but instead of sending arguments separated by , instead it sends a single array AS the arguments (The array will be resolved into individual arguments).
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
CallArray("Test", array("One", "Two", "Three")); [Args("true")] // Allow the @args variable to be made (we will use it) Function Test() { my $i = 0; foreach( @args as my $item ) { println("ARG$i: $item"); $i++; } }
Example of using first param as an array
Class Testy { Function __Construct() { CallArray(array($this, "Test"), array("One", "Two", "Three")); } [Args("true")] // Allow the @args variable to be made (we will use it) Function Test() { my $i = 0; foreach( @args as my $item ) { println("ARG$i: $item"); $i++; } } }; my $newTesty = new Testy();