mirror of https://github.com/lua/lua
new macro 'lua_checkversion' to check whether core and application are
compatible
This commit is contained in:
parent
81ede6bfce
commit
d2ebdc045b
12
lapi.c
12
lapi.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lapi.c,v 2.67 2008/07/04 18:27:11 roberto Exp roberto $
|
||||
** $Id: lapi.c,v 2.68 2008/08/01 17:01:16 roberto Exp roberto $
|
||||
** Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -121,6 +121,16 @@ LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {
|
|||
}
|
||||
|
||||
|
||||
LUA_API void lua_checkversion_ (lua_State *L, int version) {
|
||||
lua_lock(L);
|
||||
if (version != LUA_VERSION_NUM)
|
||||
luaG_runerror(L, "application and Lua core using different Lua versions");
|
||||
if (G(L)->nilobjp != luaO_nilobject)
|
||||
luaG_runerror(L, "application using two incompatible Lua VMs");
|
||||
lua_unlock(L);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** basic stack manipulation
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lauxlib.c,v 1.180 2009/02/13 19:39:34 roberto Exp roberto $
|
||||
** $Id: lauxlib.c,v 1.181 2009/02/17 14:31:16 roberto Exp roberto $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -585,6 +585,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);
|
||||
if (libname) {
|
||||
/* check whether lib already exists */
|
||||
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
|
||||
|
|
3
lstate.c
3
lstate.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lstate.c,v 2.47 2008/08/26 13:27:42 roberto Exp roberto $
|
||||
** $Id: lstate.c,v 2.48 2009/02/17 19:47:58 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -175,6 +175,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
|
|||
setnilvalue(registry(L));
|
||||
luaZ_initbuffer(L, &g->buff);
|
||||
g->panic = NULL;
|
||||
g->nilobjp = luaO_nilobject;
|
||||
g->gcstate = GCSpause;
|
||||
g->rootgc = obj2gco(L);
|
||||
g->sweepstrgc = 0;
|
||||
|
|
3
lstate.h
3
lstate.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lstate.h,v 2.35 2008/08/13 17:01:33 roberto Exp roberto $
|
||||
** $Id: lstate.h,v 2.36 2008/08/26 13:27:42 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -134,6 +134,7 @@ typedef struct global_State {
|
|||
UpVal uvhead; /* head of double-linked list of all open upvalues */
|
||||
struct Table *mt[NUM_TAGS]; /* metatables for basic types */
|
||||
TString *tmname[TM_N]; /* array with tag-method names */
|
||||
const TValue *nilobjp; /* pointer to nil object (to check consistency) */
|
||||
} global_State;
|
||||
|
||||
|
||||
|
|
6
lua.h
6
lua.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lua.h,v 1.230 2008/07/18 19:58:10 roberto Exp roberto $
|
||||
** $Id: lua.h,v 1.231 2008/08/13 14:08:49 roberto Exp roberto $
|
||||
** Lua - An Extensible Extension Language
|
||||
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
|
||||
** See Copyright Notice at the end of this file
|
||||
|
@ -115,6 +115,10 @@ LUA_API lua_State *(lua_newthread) (lua_State *L);
|
|||
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
|
||||
|
||||
|
||||
LUA_API void lua_checkversion_ (lua_State *L, int version);
|
||||
#define lua_checkversion(L) (lua_checkversion_(L, LUA_VERSION_NUM))
|
||||
|
||||
|
||||
/*
|
||||
** basic stack manipulation
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue