lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Sorry, I didn't notice the recursive call (it's late).

-----Original Message-----
From: Peter Prade [mailto:prade@phenomic.net] 
Sent: Tuesday, November 27, 2001 12:37 AM
To: Curt Carpenter
Subject: RE: Table element addressing syntax


whats wrong with recursion (as in my example)?

Regards,
Peter

> -----Original Message-----
> From: owner-lua-l@tecgraf.puc-rio.br 
> [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Curt Carpenter
> Sent: Tuesday, November 27, 2001 9:13 AM
> To: Multiple recipients of list
> Subject: RE: Table element addressing syntax
> 
> 
> > untested code:
> > 
> > function GetElement(table, field)
> > 	local pos = strfind(field,".")
> > 	if pos then 
> > 		return GetElement(table[strsub(field,1,pos-1)],
> strsub(field,pos+1))
> > 	end
> > 	return table[field]
> > end
> 
> That's a step in the right direction. I guess for an arbitrary field 
> string, which may have any number of periods, you just iteratively get

> the next table, get the appropriate field, rinse, and repeat.
> 
> Thanks,
> 
> Curt