diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-02-18 14:20:56 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-02-18 14:20:56 -0300 |
commit | d2ebdc045bae7c8ed0e62729ca455444c076b1bb (patch) | |
tree | 3237f58be972a4e328380e6ec1f96bbf1b8b70d4 | |
parent | 81ede6bfcedb9304974110e00a2a4ba301afb4f7 (diff) | |
download | lua-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.c | 12 | ||||
-rw-r--r-- | lauxlib.c | 3 | ||||
-rw-r--r-- | lstate.c | 3 | ||||
-rw-r--r-- | lstate.h | 3 | ||||
-rw-r--r-- | lua.h | 6 |
5 files changed, 22 insertions, 5 deletions
@@ -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 | ||
124 | LUA_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 |
@@ -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 | ||
586 | LUALIB_API void luaL_register (lua_State *L, const char *libname, | 586 | LUALIB_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); |
@@ -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; |
@@ -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 | ||
@@ -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); | |||
115 | LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); | 115 | LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); |
116 | 116 | ||
117 | 117 | ||
118 | LUA_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 | */ |