lua-users home
lua-l archive

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


On 2012-12-14 11:42 AM, "Jorge" <xxopxe@gmail.com> wrote:
>
> Here comes a couple related questions:
>
> 1. when defining an API for a enable/disable type call, is nil supposed to be accepted as false, or not? In other words, is better to force to provide true/false, or just anything and then evaluate it to true or false?
> This is:
>
> ----------------------
> function M.feature_enable(p)
>         if p then
>                 --enable
>         else
>                 --disable
>         end
>
> end
> ----------------------
>
> or
>
> ----------------------
> function M.feature_enable(p)
>         if p==true then
>                 --enable
>         elseif p==false then
>                 --disable
>         end
> end
> ----------------------

Well, you should definitely not fail silently when given some other type...