Fixed: lua_tointeger doesn't work if value has a decimal part and returns 0

--HG--
branch : develop
This commit is contained in:
kervala 2016-01-12 22:21:38 +01:00
parent 7104a6cb29
commit 49ef5a1ed7

View file

@ -253,7 +253,15 @@ inline lua_Integer CLuaState::toInteger(int index)
{ {
//H_AUTO(Lua_CLuaState_toInteger) //H_AUTO(Lua_CLuaState_toInteger)
checkIndex(index); checkIndex(index);
return lua_tointeger(_State, index); sint isnum = 0;
lua_Integer res = lua_tointegerx(_State, index, &isnum);
if (!isnum)
{
lua_Number d = lua_tonumber(_State, index);
nlwarning("Lua: Unable to convert Lua number %lf to integer", d);
res = (lua_Integer)d;
}
return res;
} }
//================================================================================ //================================================================================