From 5b01b79a4caba2bbd379f6c1ce18b3473ba52f72 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 12 Jan 2016 22:21:38 +0100 Subject: [PATCH] Fixed: lua_tointeger doesn't work if value has a decimal part and returns 0 --- code/nel/include/nel/gui/lua_helper_inline.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/code/nel/include/nel/gui/lua_helper_inline.h b/code/nel/include/nel/gui/lua_helper_inline.h index 68721cfaa..df75e6b5b 100644 --- a/code/nel/include/nel/gui/lua_helper_inline.h +++ b/code/nel/include/nel/gui/lua_helper_inline.h @@ -253,7 +253,15 @@ inline lua_Integer CLuaState::toInteger(int index) { //H_AUTO(Lua_CLuaState_toInteger) 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; } //================================================================================