lua-users home
lua-l archive

Re: Construct table from multiple values with named keys

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


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

AltStyle によって変換されたページ (->オリジナル) /