Core Function UnsetFunction
From Sputnik Wiki
(Difference between revisions)
(→Example) |
m (1 revision) |
||
(3 intermediate revisions by one user not shown) | |||
Line 5: | Line 5: | ||
=== Description === | === Description === | ||
− | Delete a previous user defined | + | Delete a previous user defined Function from Sputnik. |
==== function-name ==== | ==== function-name ==== | ||
Line 41: | Line 41: | ||
println("Lets try call it again"); | println("Lets try call it again"); | ||
println("1+2 Is: " . Add2(1, 2) ); // Notice the crash here? | println("1+2 Is: " . Add2(1, 2) ); // Notice the crash here? | ||
− | // It crashes above because the | + | // It crashes above because the function "Add2" no longer exists within Sputnik |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 57: | Line 57: | ||
// Load the function for the first time | // Load the function for the first time | ||
// This will view the string as a peice of Sputnik code (same as include()) | // This will view the string as a peice of Sputnik code (same as include()) | ||
− | Eval($Function); // Bascially it will add the | + | Eval($Function); // Bascially it will add the function "Add2" to Sputnik |
// Call the function | // Call the function | ||
Line 68: | Line 68: | ||
println("Lets try call it again"); | println("Lets try call it again"); | ||
println("1+2 Is: " . Add2(1, 2) ); // Notice the crash here? | println("1+2 Is: " . Add2(1, 2) ); // Notice the crash here? | ||
− | // It crashes above because the | + | // It crashes above because the function "Add2" no longer exists within Sputnik |
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:37, 14 June 2015
UnsetFunction( <function-name> )
Contents |
Description
Delete a previous user defined Function from Sputnik.
function-name
The function name to delete.
Return Value
Success: Returns 1.
Failure: Returns 0.
Remarks
This function is used to remove a previous added function to Sputnik for example if you have a plugin system that adds a series of functions you could make the plugin remove all functions when a command is typed.
Then you could load the plugin again basically allowing an update to your programs source code while it is still running.
Example
// Define a function called Add2 Function Add2($a, $b) { return $a + $b; } // Call the function println("1+2 Is: " . Add2(1, 2) ); // Now delete the function from Sputnik UnsetFunction("Add2"); // Try call the function again println("Lets try call it again"); println("1+2 Is: " . Add2(1, 2) ); // Notice the crash here? // It crashes above because the function "Add2" no longer exists within Sputnik
Heres an example loading the function from a String instead of hard coding it
// Make a string containing text of a FUNCTION to load this string as Sputnik code later my $Function = @" Function Add2($a, $b) { return $a + $b; } "; // Load the function for the first time // This will view the string as a peice of Sputnik code (same as include()) Eval($Function); // Bascially it will add the function "Add2" to Sputnik // Call the function println("1+2 Is: " . Add2(1, 2) ); // Now delete the function from Sputnik UnsetFunction("Add2"); // Try call the function again println("Lets try call it again"); println("1+2 Is: " . Add2(1, 2) ); // Notice the crash here? // It crashes above because the function "Add2" no longer exists within Sputnik