Browse Source

'checkversion' implemented in the auxiliary library

Roberto Ierusalimschy 16 years ago
parent
commit
4a818f068a
3 changed files with 16 additions and 5 deletions
  1. 11 2
      lauxlib.c
  2. 3 1
      lauxlib.h
  3. 2 2
      lua.c

+ 11 - 2
lauxlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lauxlib.c,v 1.185 2009/03/31 17:25:08 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.186 2009/04/02 19:54:06 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -649,7 +649,7 @@ static int libsize (const luaL_Reg *l) {
 
 LUALIB_API void luaL_register (lua_State *L, const char *libname,
                                const luaL_Reg *l) {
-  lua_checkversion(L);
+  luaL_checkversion(L);
   if (libname) {
     /* check whether lib already exists */
     luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
@@ -740,3 +740,12 @@ LUALIB_API lua_State *luaL_newstate (void) {
   return L;
 }
 
+
+LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver) {
+  const lua_Number *v = lua_version(L);
+  if (v != lua_version(NULL))
+    luaL_error(L, "application using two incompatible Lua VMs");
+  else if (*v != ver)
+    luaL_error(L, "application and Lua core using different Lua versions"
+                  "(%d x %d)", (int)*v, (int)ver);
+}

+ 3 - 1
lauxlib.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lauxlib.h,v 1.94 2008/01/03 17:07:59 roberto Exp roberto $
+** $Id: lauxlib.h,v 1.95 2009/02/13 19:39:34 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -26,6 +26,8 @@ typedef struct luaL_Reg {
 } luaL_Reg;
 
 
+LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver);
+#define luaL_checkversion(L)	luaL_checkversion_(L, LUA_VERSION_NUM)
 
 LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname,
                                 const luaL_Reg *l, int nup);

+ 2 - 2
lua.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.c,v 1.171 2008/07/11 17:51:01 roberto Exp roberto $
+** $Id: lua.c,v 1.172 2009/02/19 17:15:35 roberto Exp roberto $
 ** Lua stand-alone interpreter
 ** See Copyright Notice in lua.h
 */
@@ -343,7 +343,7 @@ static int pmain (lua_State *L) {
   lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
   luaL_openlibs(L);  /* open libraries */
   lua_gc(L, LUA_GCRESTART, 0);
-  lua_checkversion(L);
+  luaL_checkversion(L);
   s->ok = (handle_luainit(L) == LUA_OK);
   if (!s->ok) return 0;
   script = collectargs(argv, &has_i, &has_v, &has_e);