[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Construct table from multiple values with named keys
- From: Patrick Rapin <toupie300@...>
- Date: Wed, 9 May 2012 16:30:54 +0200
With Lua 5.2, we could use _ENV tricks.
But the following implementation is no shorter than the original, and
still requires a "local date = {}". It could be worthy if there are
plenty of fields to match to build the same table.
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)))