[cast]

Description

Link: [cast]
Author: Jason Huck
Category: Variable
Version: 8.x
License:
Posted: Feb. 13, 2006
Updated: Jan. 01, 0001
More by this author...
This is a shortcut to programmatically re-cast an element to a new type.

Parameters

-in custom type, required The element to re-cast.
-as string, required The target type.

Sample Usage

// testing
var('types') = array(
	'array',
	'boolean',
	'bytes',
	'date',
	'decimal',
	'duration',
	'integer',
	'map',
	'pair',
	'string',
);

iterate($types, local('t'));
	var('foo' = '2');
	cast($foo, -as=#t);
	$foo + ': ' + $foo->type;	
	'<br>\n';
/iterate;

'<hr>\n';

var('bar' = '<?xml version="1.0"?><root><record>hi</record></root>');
$bar->type;
'<br>\n';
cast($bar, -as='xml');
$bar->type;
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
define_tag(
	'cast',
	-required='in',
	-required='as',
	-priority='replace',
	-description='Casts the given object as the given type.'
);
	protect;		
		if(#as == 'bytes');
			local('x' = bytes);
			#x->importstring(string(#in));
			#in = #x;
		else;
			#in = tags->find(#as)->run( 
				-params=array(#in)
			);
		/if;
	/protect;
/define_tag;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular