lua-users home
lua-l archive

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


On Fri, Jul 27, 2007 at 04:55:34PM -0400, Ralph Hempel wrote:
> RJP Computing wrote:
> >How do you "check" for a boolean argument from the C api? For that
> >matter, I want the argument to have a default value of 'false'. I see
> >that there are a bunch of luaL_checkxxx() functions, but none for
> >boolean. There is also the set of luaL_optxxx() functions and boolean is
> >not there either.
>
> Ryan, I could not find it in the C API either, so I wrote my own
> versions based on how the other versions that check for int, string, etc
> work.
>
> Then I figured there must be a good reason why that seemingly obvious
> API call is not included and decided to use 0 and non-zero integers
> instead.
>
> Can anyone explain why these are not in the API?
>
> Ralph

Both lua_toboolean and lua_isboolean exist and can be used to do what you
want.

I have no real idea why there is no luaL_checkboolean other than to guess
that perhaps (like table copying) there wasn't a clear ability to decide
what it should do exactly. Since both true/false only and the lua
normative definition of true/false are valid.

	-Etan