Core Function isVarClass
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> isVarClass( $variable, <type> ) </pre> === Description === Check if a variable's object type is a class. === Parameters === ==== variable ==== The variable to check. ...") |
|||
Line 45: | Line 45: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Same example but this time making sure the class is a vec3 and nothing else : | + | Same example but this time making sure the class is a vec3 and nothing else: |
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> |
Revision as of 20:23, 4 December 2011
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" );