Browse Source

'luaL_checkversion' also checks convertions (number to integer types)

Roberto Ierusalimschy 14 years ago
parent
commit
9be89a1864
1 changed files with 8 additions and 1 deletions
  1. 8 1
      lauxlib.c

+ 8 - 1
lauxlib.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lauxlib.c,v 1.222 2010/10/25 19:01:37 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.223 2010/10/25 20:31:11 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -876,5 +876,12 @@ LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver) {
   else if (*v != ver)
   else if (*v != ver)
     luaL_error(L, "version mismatch: app. needs %d, Lua core provides %f",
     luaL_error(L, "version mismatch: app. needs %d, Lua core provides %f",
                   ver, *v);
                   ver, *v);
+  /* check conversions number -> integer types */
+  lua_pushnumber(L, -(lua_Number)0x1234);
+  if (lua_tointeger(L, -1) != -0x1234 ||
+      lua_tounsigned(L, -1) != (lua_Unsigned)-0x1234)
+    luaL_error(L, "bad conversion number->int;"
+                  " must recompile Lua with proper settings");
+  lua_pop(L, 1);
 }
 }