diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-06-18 15:59:58 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-06-18 15:59:58 -0300 |
commit | 4a818f068aef5c598c7af9ed5a834dee5d9a9eb6 (patch) | |
tree | 319b01ad36453dac48c639148ac670f007216284 | |
parent | 1d6ebce2969d3bfe406633fd8e284ff187ce00f2 (diff) | |
download | lua-4a818f068aef5c598c7af9ed5a834dee5d9a9eb6.tar.gz lua-4a818f068aef5c598c7af9ed5a834dee5d9a9eb6.tar.bz2 lua-4a818f068aef5c598c7af9ed5a834dee5d9a9eb6.zip |
'checkversion' implemented in the auxiliary library
-rw-r--r-- | lauxlib.c | 13 | ||||
-rw-r--r-- | lauxlib.h | 4 | ||||
-rw-r--r-- | lua.c | 4 |
3 files changed, 16 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.185 2009/03/31 17:25:08 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.186 2009/04/02 19:54:06 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -649,7 +649,7 @@ static int libsize (const luaL_Reg *l) { | |||
649 | 649 | ||
650 | LUALIB_API void luaL_register (lua_State *L, const char *libname, | 650 | LUALIB_API void luaL_register (lua_State *L, const char *libname, |
651 | const luaL_Reg *l) { | 651 | const luaL_Reg *l) { |
652 | lua_checkversion(L); | 652 | luaL_checkversion(L); |
653 | if (libname) { | 653 | if (libname) { |
654 | /* check whether lib already exists */ | 654 | /* check whether lib already exists */ |
655 | luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); | 655 | luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); |
@@ -740,3 +740,12 @@ LUALIB_API lua_State *luaL_newstate (void) { | |||
740 | return L; | 740 | return L; |
741 | } | 741 | } |
742 | 742 | ||
743 | |||
744 | LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver) { | ||
745 | const lua_Number *v = lua_version(L); | ||
746 | if (v != lua_version(NULL)) | ||
747 | luaL_error(L, "application using two incompatible Lua VMs"); | ||
748 | else if (*v != ver) | ||
749 | luaL_error(L, "application and Lua core using different Lua versions" | ||
750 | "(%d x %d)", (int)*v, (int)ver); | ||
751 | } | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.h,v 1.94 2008/01/03 17:07:59 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.95 2009/02/13 19:39:34 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -26,6 +26,8 @@ typedef struct luaL_Reg { | |||
26 | } luaL_Reg; | 26 | } luaL_Reg; |
27 | 27 | ||
28 | 28 | ||
29 | LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver); | ||
30 | #define luaL_checkversion(L) luaL_checkversion_(L, LUA_VERSION_NUM) | ||
29 | 31 | ||
30 | LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname, | 32 | LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname, |
31 | const luaL_Reg *l, int nup); | 33 | const luaL_Reg *l, int nup); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.171 2008/07/11 17:51:01 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.172 2009/02/19 17:15:35 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -343,7 +343,7 @@ static int pmain (lua_State *L) { | |||
343 | lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ | 343 | lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ |
344 | luaL_openlibs(L); /* open libraries */ | 344 | luaL_openlibs(L); /* open libraries */ |
345 | lua_gc(L, LUA_GCRESTART, 0); | 345 | lua_gc(L, LUA_GCRESTART, 0); |
346 | lua_checkversion(L); | 346 | luaL_checkversion(L); |
347 | s->ok = (handle_luainit(L) == LUA_OK); | 347 | s->ok = (handle_luainit(L) == LUA_OK); |
348 | if (!s->ok) return 0; | 348 | if (!s->ok) return 0; |
349 | script = collectargs(argv, &has_i, &has_v, &has_e); | 349 | script = collectargs(argv, &has_i, &has_v, &has_e); |