[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Construct table from multiple values with named keys
- From: Egor Skriptunoff <egor.skriptunoff@...>
- Date: Wed, 9 May 2012 18:05:27 +0300
On 5/9/12, Patrick Rapin <toupie300@gmail.com> wrote:
> With Lua 5.2, we could use _ENV tricks.
>
> local date = {}
> do
> local _ENV = date
> day, month, year = startdate:match("(%d%d)/(%d%d)/(%d%d%d%d)")
> end
> print(os.time(date))
>
> A variation using a function call (maybe more readable):
>
> local function parsedate(str)
> local _ENV = {}
> day, month, year = str:match("(%d%d)/(%d%d)/(%d%d%d%d)")
> return _ENV
> end
> print(os.time(parsedate(startdate)))
Unreadable, but one-line-solution :-)
print(os.time((function(d,m,y)return{day=d,month=m,year=y}end)(startdate:match('(%d%d)/(%d%d)/(%d%d%d%d)'))))