Core Function isVarClass

From Sputnik Wiki
Revision as of 20:23, 4 December 2011 by Alexpja (Talk | contribs)
Jump to: navigation, search
isVarClass( $variable, <type> )

Contents

Description

Check if a variable's object type is a class.

Parameters

variable

The variable to check.

Return Value

Success: Returns 1.

Failure: Returns 0 if parameter is not an array variable.

Remarks

Can be useful to validate array/non-array parameters to user-defined functions.

Example

A simple example to see if a variable is a class variable :

Class Vec3
{
	my $x = 0;
	my $y = 0;
	my $z = 0;
	Function Vec3($x1 = 0, $y1 = 0, $z1 = 0)
	{
		$this->$x = (double)$x1;
		$this->$y = (double)$y1;
		$this->$z = (double)$z1;
	}
};
$cat1 = new Vec3(10, 20, 30);
println( isVarClass($cat1) ? "TRUE" : "FALSE" );
println( isVarClass($moo) ? "TRUE" : "FALSE" );

Same example but this time making sure the class is a vec3 and nothing else:

Class Vec3
{
	my $x = 0;
	my $y = 0;
	my $z = 0;
	Function Vec3($x1 = 0, $y1 = 0, $z1 = 0)
	{
		$this->$x = (double)$x1;
		$this->$y = (double)$y1;
		$this->$z = (double)$z1;
	}
};
$cat1 = new Vec3(10, 20, 30);
println( isVarClass($cat1, "vec3") ? "TRUE" : "FALSE" );
println( isVarClass($moo, "vec3") ? "TRUE" : "FALSE" );
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox