Core Function UnsetFunction

From Sputnik Wiki
Jump to: navigation, search
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