[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: luaL_optboolean ?
- From: Etan Reisner <deryni@...>
- Date: Tue, 11 Sep 2007 23:22:46 -0400
On Wed, Sep 12, 2007 at 12:44:01PM +1000, Daniel Collins wrote:
> I was just wondering why the aux library provides luaL_opt* functions
> for integers, numbers and strings but not for booleans. It is not a big
> deal since I just define my own as
> int luaL_optboolean (lua_State *L, int narg, int def)
> {
> return lua_isboolean(L, narg) ? lua_toboolean(L, narg) :
> def;
> }
>
> I am just curious about why some types were chosen for the opt functions
> and some were not.
>
> - DC
I think the general answer is because that is only one of the two possible
meanings such a function could have and that definition is in fact not in
line with the standard lua interpretation of what a valid 'true' value is,
namely that anything other than false or nil is true in boolean tests.
Therefore, given that there is no one right answer a default function
wasn't given especially since writing either version is trivially easy
should someone need it.
Obviously, I wasn't involved in the design but that is the best reason I
can imagine.
-Etan