Lasso Soft Inc. > Home

[trait_serializable(auto)]

Linktrait_serializable(auto)
AuthorKe Carlton
CategorySession
Version9.x
LicensePublic Domain
Posted17 Oct 2012
Updated17 Oct 2012
More by this author...

Description

This extends trait_serializable by adding an automatic mode which automatically serialises and deserialises public data members. Currently disregards inheritance.

Sample Usage

session_start('sessionname',-path='/')
session_addvar('sessionname','test')

define user_example => type {
    trait { import trait_serializable }     
	data 
    	public firstname = '',
    	public lastname = ''
    
	public asstring => .firstname + ' ' + .lastname
}


'Current: ' + var(test)

$test = user_example
$test->firstname = 'Bob'
$test->lastname = 'Smith ' + date->second

'\rNew: ' + $test

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.

define	trait_serializable->acceptdeserializedelement(d::serialization_element) => protect => {
	local(tag) = tag(#d->key+'=')
	self->\#tag(#d->value)
}

define	trait_serializable->serializationElements() => {
	local(m,t,out = array)
	with sig in .listmethods 
	do {
		if(#sig->typename == .type ) => {
			#m = #sig->methodname->asstring
			if(#m->beginswith('\'') && #m->endswith('\'')) => {
				#t = #sig->methodname
				#m->replace('\'','')
				#m->replace('=','')
				#out->insert(
					serialization_element(
						#m,self->\#t()
					)
				)                
			}
		}
	}

	return #out->asstaticarray
}

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

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