[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Construct table from multiple values with named keys
- From: Kevin Martin <kev82@...>
- Date: Wed, 9 May 2012 13:32:47 +0100
Given a function that returns multiple values, is there a way to construct a table, but where each value is assigned a name rather than an index
The effect I'm looking for is
> local date = {}
> date.day, date.month, date.year = startdate:match("(%d%d)/(%d%d)/(%d%d%d%d)")
> print(os.time(date))
But without declaring the local date.
Obviously
> print(os.time({startdate:match("(%d%d)/(%d%d)/(%d%d%d%d)")}))
doesn't work because the values are assign to indices 1, 2, and 3
Nor does
> print(os.time({day, month, year = startdate:match("(%d%d)/(%d%d)/(%d%d%d%d)")}))
because it interprets day and month as values rather than keys.
Thanks,
Kev