lua-users home
lua-l archive

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

On 7/27/07, Etan Reisner <> wrote:
Both lua_toboolean and lua_isboolean exist and can be used to do what you

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.


I found a solution to both the optional arguments and the "check" in luaxx. Here is the code for completeness.

bool as( bool default_bool, int index = -1 )
    if ( lua_isboolean( L, index ) )
        return lua_toboolean( L, index );
        return default_bool;

state& to( bool& boolean, int index = -1 )
    if ( lua_isboolean( L, index ) )
        boolean = lua_toboolean( L, index );
        throw bad_conversion( "Cannot convert non 'boolean' value to bool" );

    return *this;

I still would like to know why they are missing from the C api.
RJP Computing