luaA_getopt_number(): also return def if stack top is neither number nor nil

Signed-off-by: Gregor Best <farhaven@googlemail.com>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Gregor Best 2009-04-06 09:47:44 +02:00 committed by Julien Danjou
parent 2ca7149501
commit b0975c2360
1 changed files with 3 additions and 2 deletions

5
luaa.h
View File

@ -135,9 +135,10 @@ static inline lua_Number
luaA_getopt_number(lua_State *L, int idx, const char *name, lua_Number def)
{
lua_getfield(L, idx, name);
lua_Number n = luaL_optnumber(L, -1, def);
if (lua_isnil(L, -1) || lua_isnumber(L, -1))
def = luaL_optnumber(L, -1, def);
lua_pop(L, 1);
return n;
return def;
}
static inline const char *