[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: luaL_checkboolean() equivalent?
- From: Martin Guy <martinwguy@...>
- Date: Fri, 22 Jul 2011 21:02:59 +0200
Hi
I'm new to the Lua C interface and wonder if comeone can suggest
the best Lua idiom to receive a boolean parameter into a C function?
I was hoping for something like:
int self_destruct( lua_state *L )
{
bool are_you_sure = luaL_checkboolean( L, 1 );
but luaL_checkboolean doesn't exist. Of course, it couldn't fail with
a type error, because nil and false are false, while true and
everything else are true, but do I really have to check the type of
the parameter and check for nil and false explicitly, with some garply
like:
bool are_you_sure = ! ( lua_isnil( L, 1 ) || (lua_isboolean( L, 1 )
&& ! lua_toboolean( L, 1 ) );
or is there a cleaner way?
Cheers
M