Core Function UnsetFunction

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> UnsetFunction( <function-name> ) </pre> === Description === Delete a previous user defined function from Sputnik. ==== function-name ==== The function name to delete. ...")
 
m (1 revision)
 
(4 intermediate revisions by one user not shown)
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
  
Delete a previous user defined function from Sputnik.
+
Delete a previous user defined Function from Sputnik.
  
 
==== function-name ====
 
==== function-name ====
Line 24: Line 24:
  
 
=== Example ===
 
=== Example ===
 +
 +
<syntaxhighlight lang="sputnik">
 +
// 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
 +
</syntaxhighlight>
 +
 +
Heres an example loading the function from a String instead of hard coding it
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
Line 36: 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 funciton "Add2" to Sputnik
+
Eval($Function); // Bascially it will add the function "Add2" to Sputnik
  
 
// Call the function
 
// Call the function
Line 47: 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 funciton "Add2" no longer exists within Sputnik
+
// 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
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox