commit 4a818f068aef5c598c7af9ed5a834dee5d9a9eb6
parent 1d6ebce2969d3bfe406633fd8e284ff187ce00f2
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Thu, 18 Jun 2009 15:59:34 -0300
'checkversion' implemented in the auxiliary library
Diffstat:
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/lauxlib.c b/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);
+}
diff --git a/lauxlib.h b/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);
diff --git a/lua.c b/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);