lua-users home
lua-l archive

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


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)'))))