lua-users home
lua-l archive

Re: Shorten long boolean IF conditions?

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


On 2011年8月19日 09:09:28 +0200, Daniel Hertrich wrote:
if strCustomPropertyValue in ("inbox", "today", "thisweek",
"thismonth", "thisyear", "later", "someday", "archive",
"otherpersons") then
...
end
Is something like this possible in Lua? I have not found a way yet.
for _,x in ipairs{"inbox", "today", "thisweek", "thismonth",
"thisyear", "later", "someday", "archive", "otherpersons"} do
 if strCustomPropertyValue == x then
 ...
 end
end
Or you could convert it to a Lua-style Set (see
http://www.lua.org/pil/13.1.html) first:
if (Set.new{"inbox", "today", "thisweek", "thismonth",
"thisyear", "later", "someday", "archive",
"otherpersons"})[strCustomPropertyValue] then
 ...
end
--
Pierre 'catwell' Chapuis

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