Re: Shorten long boolean IF conditions?
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Shorten long boolean IF conditions?
- From: Dirk Laurie <dpl@...>
- Date: 2011年8月19日 09:51:56 +0200
On Fri, Aug 19, 2011 at 09:37:49AM +0200, Gregory Bonik wrote:
> Daniel Hertrich wrote:
> > I'd like to shorten an if condition such as:
>
> > if strCustomPropertyValue == "inbox" or strCustomPropertyValue ==
> > "today" or strCustomPropertyValue == "thisweek" or
> > strCustomPropertyValue == "thismonth" or strCustomPropertyValue ==
> > "thisyear" or strCustomPropertyValue == "later" or
> > strCustomPropertyValue == "someday" or strCustomPropertyValue ==
> > "archive" or strCustomPropertyValue == "otherpersons" then
> > ...
> > end
>
> An alternative to the solution with tables is a vararg function:
>
> function is_one_of(value, ...)
> for k, v in ipairs(arg) do
> if v == value then return true end
> end
> end
>
That version works in Lua 5.0 and Lua 5.1, but not Lua 5.2.
This one works in Lua 5.1 and Lua 5.2, but not Lua 5.0.
function is_one_of(value, ...)
for k, v in ipairs{...} do
if v == value then return true end
end
end
Dirk