aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-02-18 14:20:56 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-02-18 14:20:56 -0300
commitd2ebdc045bae7c8ed0e62729ca455444c076b1bb (patch)
tree3237f58be972a4e328380e6ec1f96bbf1b8b70d4
parent81ede6bfcedb9304974110e00a2a4ba301afb4f7 (diff)
downloadlua-d2ebdc045bae7c8ed0e62729ca455444c076b1bb.tar.gz
lua-d2ebdc045bae7c8ed0e62729ca455444c076b1bb.tar.bz2
lua-d2ebdc045bae7c8ed0e62729ca455444c076b1bb.zip
new macro 'lua_checkversion' to check whether core and application are
compatible
-rw-r--r--lapi.c12
-rw-r--r--lauxlib.c3
-rw-r--r--lstate.c3
-rw-r--r--lstate.h3
-rw-r--r--lua.h6
5 files changed, 22 insertions, 5 deletions
diff --git a/lapi.c b/lapi.c
index 9af75b17..86b591c4 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.67 2008/07/04 18:27:11 roberto Exp roberto $ 2** $Id: lapi.c,v 2.68 2008/08/01 17:01:16 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -121,6 +121,16 @@ LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {
121} 121}
122 122
123 123
124LUA_API void lua_checkversion_ (lua_State *L, int version) {
125 lua_lock(L);
126 if (version != LUA_VERSION_NUM)
127 luaG_runerror(L, "application and Lua core using different Lua versions");
128 if (G(L)->nilobjp != luaO_nilobject)
129 luaG_runerror(L, "application using two incompatible Lua VMs");
130 lua_unlock(L);
131}
132
133
124 134
125/* 135/*
126** basic stack manipulation 136** basic stack manipulation
diff --git a/lauxlib.c b/lauxlib.c
index 55ee1411..469553ae 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.180 2009/02/13 19:39:34 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.181 2009/02/17 14:31:16 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*/
@@ -585,6 +585,7 @@ static int libsize (const luaL_Reg *l) {
585 585
586LUALIB_API void luaL_register (lua_State *L, const char *libname, 586LUALIB_API void luaL_register (lua_State *L, const char *libname,
587 const luaL_Reg *l) { 587 const luaL_Reg *l) {
588 lua_checkversion(L);
588 if (libname) { 589 if (libname) {
589 /* check whether lib already exists */ 590 /* check whether lib already exists */
590 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); 591 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
diff --git a/lstate.c b/lstate.c
index be7eed91..e1a3237b 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.47 2008/08/26 13:27:42 roberto Exp roberto $ 2** $Id: lstate.c,v 2.48 2009/02/17 19:47:58 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -175,6 +175,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
175 setnilvalue(registry(L)); 175 setnilvalue(registry(L));
176 luaZ_initbuffer(L, &g->buff); 176 luaZ_initbuffer(L, &g->buff);
177 g->panic = NULL; 177 g->panic = NULL;
178 g->nilobjp = luaO_nilobject;
178 g->gcstate = GCSpause; 179 g->gcstate = GCSpause;
179 g->rootgc = obj2gco(L); 180 g->rootgc = obj2gco(L);
180 g->sweepstrgc = 0; 181 g->sweepstrgc = 0;
diff --git a/lstate.h b/lstate.h
index c4106562..def5d7eb 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 2.35 2008/08/13 17:01:33 roberto Exp roberto $ 2** $Id: lstate.h,v 2.36 2008/08/26 13:27:42 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -134,6 +134,7 @@ typedef struct global_State {
134 UpVal uvhead; /* head of double-linked list of all open upvalues */ 134 UpVal uvhead; /* head of double-linked list of all open upvalues */
135 struct Table *mt[NUM_TAGS]; /* metatables for basic types */ 135 struct Table *mt[NUM_TAGS]; /* metatables for basic types */
136 TString *tmname[TM_N]; /* array with tag-method names */ 136 TString *tmname[TM_N]; /* array with tag-method names */
137 const TValue *nilobjp; /* pointer to nil object (to check consistency) */
137} global_State; 138} global_State;
138 139
139 140
diff --git a/lua.h b/lua.h
index aa3a6789..82101882 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.230 2008/07/18 19:58:10 roberto Exp roberto $ 2** $Id: lua.h,v 1.231 2008/08/13 14:08:49 roberto Exp roberto $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5** See Copyright Notice at the end of this file 5** See Copyright Notice at the end of this file
@@ -115,6 +115,10 @@ LUA_API lua_State *(lua_newthread) (lua_State *L);
115LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); 115LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
116 116
117 117
118LUA_API void lua_checkversion_ (lua_State *L, int version);
119#define lua_checkversion(L) (lua_checkversion_(L, LUA_VERSION_NUM))
120
121
118/* 122/*
119** basic stack manipulation 123** basic stack manipulation
120*/ 124*/