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:
parent
2ca7149501
commit
b0975c2360
5
luaa.h
5
luaa.h
|
@ -135,9 +135,10 @@ static inline lua_Number
|
||||||
luaA_getopt_number(lua_State *L, int idx, const char *name, lua_Number def)
|
luaA_getopt_number(lua_State *L, int idx, const char *name, lua_Number def)
|
||||||
{
|
{
|
||||||
lua_getfield(L, idx, name);
|
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);
|
lua_pop(L, 1);
|
||||||
return n;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline const char *
|
static inline const char *
|
||||||
|
|
Loading…
Reference in New Issue