new function 'lua_version' (so that 'checkversion' can be implemented

in the auxiliary library)
This commit is contained in:
Roberto Ierusalimschy
2009-06-18 15:59:18 -03:00
parent bc3e02a1b7
commit 1d6ebce296
4 changed files with 12 additions and 15 deletions

14
lapi.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lapi.c,v 2.81 2009/06/17 18:38:54 roberto Exp roberto $ ** $Id: lapi.c,v 2.82 2009/06/18 16:36:40 roberto Exp roberto $
** Lua API ** Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -129,13 +129,11 @@ LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {
} }
LUA_API void lua_checkversion_ (lua_State *L, int version) { static const lua_Number l_version = LUA_VERSION_NUM;
lua_lock(L);
if (version != LUA_VERSION_NUM) LUA_API const lua_Number *lua_version (lua_State *L) {
luaG_runerror(L, "app./library not compiled with header " LUA_VERSION); if (L == NULL) return &l_version;
if (G(L)->nilobjp != luaO_nilobject) else return G(L)->version;
luaG_runerror(L, "application using multiple Lua VMs");
lua_unlock(L);
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstate.c,v 2.54 2009/04/28 19:04:36 roberto Exp roberto $ ** $Id: lstate.c,v 2.55 2009/06/01 19:09:26 roberto Exp roberto $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -208,7 +208,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
setnilvalue(registry(L)); setnilvalue(registry(L));
luaZ_initbuffer(L, &g->buff); luaZ_initbuffer(L, &g->buff);
g->panic = NULL; g->panic = NULL;
g->nilobjp = luaO_nilobject; g->version = lua_version(NULL);
g->gcstate = GCSpause; g->gcstate = GCSpause;
g->rootgc = obj2gco(L); g->rootgc = obj2gco(L);
g->sweepstrgc = 0; g->sweepstrgc = 0;

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstate.h,v 2.43 2009/04/17 22:00:01 roberto Exp roberto $ ** $Id: lstate.h,v 2.44 2009/06/01 19:09:26 roberto Exp roberto $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -148,9 +148,9 @@ typedef struct global_State {
TValue l_registry; TValue l_registry;
struct lua_State *mainthread; struct lua_State *mainthread;
UpVal uvhead; /* head of double-linked list of all open upvalues */ UpVal uvhead; /* head of double-linked list of all open upvalues */
const lua_Number *version; /* pointer to version number */
struct Table *mt[NUM_TAGS]; /* metatables for basic types */ struct Table *mt[NUM_TAGS]; /* metatables for basic types */
TString *tmname[TM_N]; /* array with tag-method names */ TString *tmname[TM_N]; /* array with tag-method names */
const TValue *nilobjp; /* pointer to nil object (to check consistency) */
} global_State; } global_State;

5
lua.h
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lua.h,v 1.238 2009/06/15 19:51:31 roberto Exp roberto $ ** $Id: lua.h,v 1.239 2009/06/17 17:49:44 roberto Exp roberto $
** Lua - An Extensible Extension Language ** Lua - An Extensible Extension Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file ** See Copyright Notice at the end of this file
@@ -118,8 +118,7 @@ LUA_API lua_State *(lua_mainthread) (lua_State *L);
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
LUA_API void lua_checkversion_ (lua_State *L, int version); LUA_API const lua_Number *lua_version (lua_State *L);
#define lua_checkversion(L) (lua_checkversion_(L, LUA_VERSION_NUM))
/* /*