Core Function VarList

From Sputnik Wiki
Jump to: navigation, search
VarList( <varScope/class> )

Contents

Description

Obtain information on all variables that exist in a given scope or class.

<varScope/class>

A variable scope (see Macros) or a class variable to scan for variables

Return Value

Success: Returns array of all found variables (Their name and information NOT their content).

Failure: Returns null.

Remarks

This is useful to grav information about variables and see how things tick a bit.

Example

Read all information about Local variables

// Define an *object* based variable
my $fox = sbNew();
{
	// Define an *binary* based variable
	my $dog = bin();
	{
		// Define an *string* based variable
		my $cat = "meow";
		// Define an *integer* based variable
		my $test = 777;
		// Get all local variables
		my $vList = VarList(@ScopeLocal);
		// Loop through and print their information
		foreach($vList as my $varName => my $varInfo)
		{
			// Extract information using KEY based List() since
			// the information is stored in KEYS and not just pushed
			// onto the array
			my List(@$Type, @$Depth, @$VarScope, @$ScopeType) = $varInfo;
			say "### Variable '$varName' BELOW ###";
			my $TypeStr = VarTypeToString($Type);
			my $VarScopeStr = VarScopeToString($VarScope);
			my $ScopeTypeStr = ScopeToString($ScopeType);
			say "Type '$Type' (as String '$TypeStr')";
			if ($Type == @typeObject)
			{
				my $ObjType = $varInfo['ObjectType'];
				my $ObjTypeStr = VarObjTypeToString($ObjType);
				say "Object Type '$ObjType' (as String '$ObjTypeStr')";
			}
			say "Depth '$Depth'";
			say "VarScope '$VarScope' (as string '$VarScopeStr')";
			say "ScopeType '$ScopeType' (as string '$ScopeTypeStr')";
			say "### Variable '$varName' ABOVE ###";
			say;
		}
	}
}
// PRINTS
// ### Variable 'cat' BELOW ###
// Type '14' (as String 'String')
// Depth '0'
// VarScope '2' (as string 'Local')
// ScopeType '3' (as string 'Block')
// ### Variable 'cat' ABOVE ###
//
// ### Variable 'test' BELOW ###
// Type '8' (as String 'Int64')
// Depth '0'
// VarScope '2' (as string 'Local')
// ScopeType '3' (as string 'Block')
// ### Variable 'test' ABOVE ###
//
// ### Variable 'varname' BELOW ###
// Type '1' (as String 'Null')
// Depth '0'
// VarScope '2' (as string 'Local')
// ScopeType '3' (as string 'Block')
// ### Variable 'varname' ABOVE ###
//
// ### Variable 'varinfo' BELOW ###
// Type '1' (as String 'Null')
// Depth '0'
// VarScope '2' (as string 'Local')
// ScopeType '3' (as string 'Block')
// ### Variable 'varinfo' ABOVE ###
//
// ### Variable 'dog' BELOW ###
// Type '17' (as String 'Binary')
// Depth '1'
// VarScope '2' (as string 'Local')
// ScopeType '3' (as string 'Block')
// ### Variable 'dog' ABOVE ###
//
// ### Variable 'fox' BELOW ###
// Type '20' (as String 'Object')
// Object Type '5' (as String 'Object')
// Depth '2'
// VarScope '2' (as string 'Local')
// ScopeType '1' (as string 'InterpInit')
// ### Variable 'fox' ABOVE ###

Read all information about Global variables

Note that sometimes stuff will appear in Globals such as @argv and other things these are Sputnik internal Global variables

// Define some global variables
Global $cat = "Hello";
Global $dog = bin();
Global $fox = sbNew();
 
// Get all global variables
my $vList = VarList(@ScopeGlobal);
// Loop through and print their information
foreach($vList as my $varName => my $varInfo)
{
	// Extract information using KEY based List() since
	// the information is stored in KEYS and not just pushed
	// onto the array
	my List(@$Type, @$VarScope, @$ScopeType) = $varInfo;
	say "### Variable '$varName' BELOW ###";
	my $TypeStr = VarTypeToString($Type);
	my $VarScopeStr = VarScopeToString($VarScope);
	my $ScopeTypeStr = ScopeToString($ScopeType);
	say "Type '$Type' (as String '$TypeStr')";
	if ($Type == @typeObject)
	{
		my $ObjType = $varInfo['ObjectType'];
		my $ObjTypeStr = VarObjTypeToString($ObjType);
		say "Object Type '$ObjType' (as String '$ObjTypeStr')";
	}
	say "VarScope '$VarScope' (as string '$VarScopeStr')";
	say "ScopeType '$ScopeType' (as string '$ScopeTypeStr')";
	say "### Variable '$varName' ABOVE ###";
	say;
}
// PRINTS
// ### Variable '@argv' BELOW ###
// Type '19' (as String 'Array')
// VarScope '2' (as string 'Local')
// ScopeType '0' (as string 'None')
// ### Variable '@argv' ABOVE ###
// 
// ### Variable 'cat' BELOW ###
// Type '14' (as String 'String')
// VarScope '2' (as string 'Local')
// ScopeType '0' (as string 'None')
// ### Variable 'cat' ABOVE ###
// 
// ### Variable 'dog' BELOW ###
// Type '17' (as String 'Binary')
// VarScope '2' (as string 'Local')
// ScopeType '0' (as string 'None')
// ### Variable 'dog' ABOVE ###
// 
// ### Variable 'fox' BELOW ###
// Type '20' (as String 'Object')
// Object Type '5' (as String 'Object')
// VarScope '2' (as string 'Local')
// ScopeType '0' (as string 'None')
// ### Variable 'fox' ABOVE ###
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox