Lasso Soft Inc. > Home

[B_UUID]

LinkB_UUID
AuthorDouglas Burchard
CategoryCustom Tag
Version8.5.x
LicensePublic Domain
Posted25 Sep 2009
Updated25 Sep 2009
More by this author...

Description

This custom prototype returns a version 4 (random) Universally Unique Identifier (UUID). For more information on UUIDs, please read the Wikipedia entry, currently at: http://en.wikipedia.org/wiki/uuid

Sample Usage

B_UUID

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.

// =====================================================================
/*
	B_UUID
	--------------------------------------------------------------------

		===========================================
		| B_UUID
		|
		===========================================
		| Tags
		-------------------------------------------
		| onCreate()						String
		| ToHex(Integer)					String
		| ToChar(Integer)					String
		| GenerateNumber(Integer,Integer)	Integer
		| GenerateUUID()					String
		|

	This custom prototype returns a version 4 (random) Universally Unique
	Identifier (UUID). For more information on UUIDs, please read the 
	Wikipedia entry, currently at:

		http://en.wikipedia.org/wiki/uuid

*/
// ---------------------------------------------------------------------
Define_Type('UUID',
		-NameSpace='B_',
		-Prototype,
		-Description='This custom prototype returns a version 4 (random) ' +
			'Universally Unique Identifier (UUID). For more information ' +
			'on UUIDs, please read the Wikipedia entry, currently at: ' +
			'http://en.wikipedia.org/wiki/uuid.');

	Define_Tag('onCreate');
		Return(String(Self -> GenerateUUID));
	/Define_Tag;

	Define_Tag('ToHex', -Required='d', -EncodeNone);
		Local('r' = (#d % (16)));
		Local('result');
		If((#d - #r) == (0));
			#result = (Self -> ToChar(#r));
		Else;
			#result = ((Self -> ToHex((#d - #r) / (16))) + (Self -> ToChar(#r)));
		/If;
		Return(#result);
	/Define_Tag;

	Define_Tag('ToChar', -Required='n', -EncodeNone);
		Local('alpha' = '0123456789abcdef');
		Return(#alpha -> Get(#n + (1)));
	/Define_Tag;

	Define_Tag('GenerateNumber', -Required='l', -Required='u', -EncodeNone);
		Local('n' = Math_Random(-Lower=(Local('l') - (1)), -Upper=Local('u')));
		#n = ((#n < Local('l')) ? Local('u') | (#n));
		Return(#n);
	/Define_Tag;

	Define_Tag('GenerateUUID', -EncodeNone);
		Local('random_bytes' = String);

		#random_bytes += (Self -> ToHex(_date_msec));
		#random_bytes -> Reverse;
		While((#random_bytes -> Size) < (30));
			#random_bytes += (Self -> ToHex(Self -> GenerateNumber((0), (15))));
		/While;
		#random_bytes -> Lowercase;
		#random_bytes = String_Insert(#random_bytes, -Position=(9), -Text='-');
		#random_bytes = String_Insert(#random_bytes, -Position=(14), -Text='-4');
		#random_bytes = String_Insert(#random_bytes, -Position=(19), -Text=('-' + (Array('8','9','a','b') -> Get(Self -> ToHex(Self -> GenerateNumber((1), (4)))))));
		#random_bytes = String_Insert(#random_bytes, -Position=(24), -Text='-');

		Return(#random_bytes);
	/Define_Tag;

/Define_Type;
// =====================================================================

Comments

13 Nov 2012, Gary Sprague

This tag is very useful, but I have had issues...

I was glad to find this UUID custom tag by Doug. I've been using this for over a year. After several months, however, it will cause Lasso to throw an error when used. At that point I have to restart LassoService.

The general error is:
The position passed to "get" was invalid.
at: ToChar with params: -7
at: ToHex with params: -7
at: ToHex with params: -127
at: ToHex with params: -2041
at: ToHex with params: -32670
at: ToHex with params: -522734
at: ToHex with params: -8363749
at: ToHex with params: -133819984
at: ToHex with params: -2141119750
at: GenerateUUID
at: onCreate
at: (my lasso page)

Please log in to comment

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2014 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft