From 1d6ebce2969d3bfe406633fd8e284ff187ce00f2 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 18 Jun 2009 15:59:18 -0300 Subject: [PATCH] new function 'lua_version' (so that 'checkversion' can be implemented in the auxiliary library) --- lapi.c | 14 ++++++-------- lstate.c | 4 ++-- lstate.h | 4 ++-- lua.h | 5 ++--- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lapi.c b/lapi.c index f6e8b034..dd8a96ac 100644 --- a/lapi.c +++ b/lapi.c @@ -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 ** 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) { - lua_lock(L); - if (version != LUA_VERSION_NUM) - luaG_runerror(L, "app./library not compiled with header " LUA_VERSION); - if (G(L)->nilobjp != luaO_nilobject) - luaG_runerror(L, "application using multiple Lua VMs"); - lua_unlock(L); +static const lua_Number l_version = LUA_VERSION_NUM; + +LUA_API const lua_Number *lua_version (lua_State *L) { + if (L == NULL) return &l_version; + else return G(L)->version; } diff --git a/lstate.c b/lstate.c index c6ca5b9b..3268209e 100644 --- a/lstate.c +++ b/lstate.c @@ -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 ** See Copyright Notice in lua.h */ @@ -208,7 +208,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->version = lua_version(NULL); g->gcstate = GCSpause; g->rootgc = obj2gco(L); g->sweepstrgc = 0; diff --git a/lstate.h b/lstate.h index 6751c0a1..783e51cf 100644 --- a/lstate.h +++ b/lstate.h @@ -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 ** See Copyright Notice in lua.h */ @@ -148,9 +148,9 @@ typedef struct global_State { TValue l_registry; struct lua_State *mainthread; 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 */ TString *tmname[TM_N]; /* array with tag-method names */ - const TValue *nilobjp; /* pointer to nil object (to check consistency) */ } global_State; diff --git a/lua.h b/lua.h index aa242e8e..edeafe7a 100644 --- a/lua.h +++ b/lua.h @@ -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.org, PUC-Rio, Brazil (http://www.lua.org) ** 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 void lua_checkversion_ (lua_State *L, int version); -#define lua_checkversion(L) (lua_checkversion_(L, LUA_VERSION_NUM)) +LUA_API const lua_Number *lua_version (lua_State *L); /*