Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[Lua] Fixed integer/double conversion problem
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Thu, 23 Jul 2015 13:17:30 +0000 (15:17 +0200)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Thu, 15 Oct 2015 17:17:18 +0000 (19:17 +0200)
  - This bug would change integers to doubles when lua was used
    to actually run the simulation

src/bindings/lua/lua_state_cloner.c

index 47f8b4f..dfee7ed 100644 (file)
@@ -259,7 +259,12 @@ static void sglua_copy_nil(lua_State* src, lua_State* dst) {
  * @param dst destination state
  */
 static void sglua_copy_number(lua_State* src, lua_State* dst) {
-  lua_pushnumber(dst, lua_tonumber(src, -1));
+  lua_Number n = lua_tonumber(src, -1);
+  if ( ((lua_Integer) n) == n) {
+    lua_pushinteger(dst, lua_tointeger(src, -1));
+  }
+  else
+    lua_pushnumber(dst, lua_tonumber(src, -1));
 }
 
 /**