From 79c8edb6c423b48270c1f61df6fd5a889ca5da0e Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 17 Jul 2002 13:25:13 -0300 Subject: [PATCH] new names for light userdata operations --- lapi.c | 9 ++++++--- lbaselib.c | 10 +++++----- ldblib.c | 8 ++++---- lgc.c | 4 ++-- liolib.c | 4 ++-- lobject.c | 4 ++-- lobject.h | 6 +++--- ltable.c | 4 ++-- ltests.c | 9 +++++---- ltests.h | 7 +++---- ltm.c | 4 ++-- lua.h | 18 +++++++++--------- lvm.c | 4 ++-- 13 files changed, 47 insertions(+), 44 deletions(-) diff --git a/lapi.c b/lapi.c index 67fe9ddc..ebb16a38 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 1.203 2002/06/25 19:15:41 roberto Exp roberto $ +** $Id: lapi.c,v 1.204 2002/06/26 19:28:44 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -305,7 +305,7 @@ LUA_API void *lua_touserdata (lua_State *L, int index) { if (o == NULL) return NULL; switch (ttype(o)) { case LUA_TUSERDATA: return (uvalue(o) + 1); - case LUA_TUDATAVAL: return pvalue(o); + case LUA_TLIGHTUSERDATA: return pvalue(o); default: return NULL; } } @@ -318,6 +318,9 @@ LUA_API const void *lua_topointer (lua_State *L, int index) { switch (ttype(o)) { case LUA_TTABLE: return hvalue(o); case LUA_TFUNCTION: return clvalue(o); + case LUA_TUSERDATA: + case LUA_TLIGHTUSERDATA: + return lua_touserdata(L, index); default: return NULL; } } @@ -407,7 +410,7 @@ LUA_API void lua_pushboolean (lua_State *L, int b) { } -LUA_API void lua_pushudataval (lua_State *L, void *p) { +LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { lua_lock(L); setpvalue(L->top, p); api_incr_top(L); diff --git a/lbaselib.c b/lbaselib.c index 3edd8050..39f1544e 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.89 2002/07/01 19:23:58 roberto Exp roberto $ +** $Id: lbaselib.c,v 1.90 2002/07/04 17:58:02 roberto Exp roberto $ ** Basic library ** See Copyright Notice in lua.h */ @@ -310,7 +310,7 @@ static int luaB_tostring (lua_State *L) { sprintf(buff, "function: %p", lua_topointer(L, 1)); break; case LUA_TUSERDATA: - case LUA_TUDATAVAL: + case LUA_TLIGHTUSERDATA: sprintf(buff, "userdata: %p", lua_touserdata(L, 1)); break; case LUA_TNIL: @@ -484,7 +484,7 @@ static const luaL_reg base_funcs[] = { static int luaB_resume (lua_State *L) { - lua_State *co = (lua_State *)lua_getfrombox(L, lua_upvalueindex(1)); + lua_State *co = (lua_State *)lua_unboxpointer(L, lua_upvalueindex(1)); int status; lua_settop(L, 0); status = lua_resume(L, co); @@ -503,7 +503,7 @@ static int luaB_resume (lua_State *L) { static int gc_coroutine (lua_State *L) { - lua_State *co = (lua_State *)lua_getfrombox(L, 1); + lua_State *co = (lua_State *)lua_unboxpointer(L, 1); lua_closethread(L, co); return 0; } @@ -526,7 +526,7 @@ static int luaB_coroutine (lua_State *L) { lua_unref(L, ref); } lua_cobegin(NL, n-1); - lua_newpointerbox(L, NL); + lua_boxpointer(L, NL); lua_pushliteral(L, "Coroutine"); lua_rawget(L, LUA_REGISTRYINDEX); lua_setmetatable(L, -2); diff --git a/ldblib.c b/ldblib.c index fc056cce..13e328d3 100644 --- a/ldblib.c +++ b/ldblib.c @@ -1,5 +1,5 @@ /* -** $Id: ldblib.c,v 1.62 2002/07/08 18:21:33 roberto Exp roberto $ +** $Id: ldblib.c,v 1.63 2002/07/08 20:22:08 roberto Exp roberto $ ** Interface from Lua to its debug API ** See Copyright Notice in lua.h */ @@ -113,7 +113,7 @@ static const char KEY_HOOK = 'h'; static void hookf (lua_State *L, lua_Debug *ar) { static const char *const hooknames[] = {"call", "return", "line", "count"}; - lua_pushudataval(L, (void *)&KEY_HOOK); + lua_pushlightuserdata(L, (void *)&KEY_HOOK); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_isfunction(L, -1)) { lua_pushstring(L, hooknames[(int)ar->event]); @@ -157,7 +157,7 @@ static int sethook (lua_State *L) { luaL_check_type(L, 1, LUA_TFUNCTION); lua_sethook(L, hookf, makemask(smask, count)); } - lua_pushudataval(L, (void *)&KEY_HOOK); + lua_pushlightuserdata(L, (void *)&KEY_HOOK); lua_pushvalue(L, 1); lua_rawset(L, LUA_REGISTRYINDEX); /* set new hook */ return 0; @@ -167,7 +167,7 @@ static int sethook (lua_State *L) { static int gethook (lua_State *L) { char buff[5]; int mask = lua_gethookmask(L); - lua_pushudataval(L, (void *)&KEY_HOOK); + lua_pushlightuserdata(L, (void *)&KEY_HOOK); lua_rawget(L, LUA_REGISTRYINDEX); /* get hook */ lua_pushstring(L, unmakemask(mask, buff)); lua_pushnumber(L, lua_getmaskcount(mask)); diff --git a/lgc.c b/lgc.c index 991ff51d..47513769 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 1.141 2002/07/04 17:57:42 roberto Exp $ +** $Id: lgc.c,v 1.142 2002/07/08 18:21:33 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -58,7 +58,7 @@ typedef struct GCState { #define ismarkable(o) (!((1 << ttype(o)) & \ ((1 << LUA_TNIL) | (1 << LUA_TNUMBER) | \ - (1 << LUA_TBOOLEAN) | (1 << LUA_TUDATAVAL)))) + (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA)))) static void reallymarkobject (GCState *st, TObject *o); diff --git a/liolib.c b/liolib.c index e67d61fd..2798e2bf 100644 --- a/liolib.c +++ b/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 2.12 2002/06/26 16:37:13 roberto Exp roberto $ +** $Id: liolib.c,v 2.13 2002/07/12 18:54:53 roberto Exp roberto $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -67,7 +67,7 @@ static FILE *tofile (lua_State *L, int findex) { static void newfile (lua_State *L, FILE *f) { - lua_newpointerbox(L, f); + lua_boxpointer(L, f); lua_pushliteral(L, FILEHANDLE); lua_rawget(L, LUA_REGISTRYINDEX); lua_setmetatable(L, -2); diff --git a/lobject.c b/lobject.c index 86d386df..d2605ebd 100644 --- a/lobject.c +++ b/lobject.c @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 1.83 2002/06/05 12:34:19 roberto Exp roberto $ +** $Id: lobject.c,v 1.84 2002/06/13 13:39:55 roberto Exp roberto $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ @@ -66,7 +66,7 @@ int luaO_rawequalObj (const TObject *t1, const TObject *t2) { return tsvalue(t1) == tsvalue(t2); case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ - case LUA_TUDATAVAL: + case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); case LUA_TUSERDATA: return uvalue(t1) == uvalue(t2); diff --git a/lobject.h b/lobject.h index 616b897c..0e800c16 100644 --- a/lobject.h +++ b/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 1.138 2002/06/24 20:17:59 roberto Exp roberto $ +** $Id: lobject.h,v 1.139 2002/07/01 17:06:58 roberto Exp roberto $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ @@ -35,7 +35,7 @@ typedef struct lua_TObject { /* Macros to access values */ #define ttype(o) ((o)->tt) -#define pvalue(o) check_exp(ttype(o)==LUA_TUDATAVAL, (o)->value.p) +#define pvalue(o) check_exp(ttype(o)==LUA_TLIGHTUSERDATA, (o)->value.p) #define nvalue(o) check_exp(ttype(o)==LUA_TNUMBER, (o)->value.n) #define tsvalue(o) check_exp(ttype(o)==LUA_TSTRING, (o)->value.ts) #define uvalue(o) check_exp(ttype(o)==LUA_TUSERDATA, (o)->value.u) @@ -54,7 +54,7 @@ typedef struct lua_TObject { check_exp(ttype(obj)==LUA_TNUMBER, (obj)->value.n=(x)) #define setpvalue(obj,x) \ - { TObject *i_o=(obj); i_o->tt=LUA_TUDATAVAL; i_o->value.p=(x); } + { TObject *i_o=(obj); i_o->tt=LUA_TLIGHTUSERDATA; i_o->value.p=(x); } #define setbvalue(obj,x) \ { TObject *i_o=(obj); i_o->tt=LUA_TBOOLEAN; i_o->value.b=(x); } diff --git a/ltable.c b/ltable.c index baab5ea3..2951def0 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 1.112 2002/07/01 19:31:10 roberto Exp roberto $ +** $Id: ltable.c,v 1.113 2002/07/02 17:54:23 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -80,7 +80,7 @@ Node *luaH_mainposition (const Table *t, const TObject *key) { return hashstr(t, tsvalue(key)); case LUA_TBOOLEAN: return hashboolean(t, bvalue(key)); - case LUA_TUDATAVAL: + case LUA_TLIGHTUSERDATA: return hashpointer(t, pvalue(key)); case LUA_TUSERDATA: return hashpointer(t, uvalue(key)); diff --git a/ltests.c b/ltests.c index 99623541..4dee632c 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 1.128 2002/06/25 19:16:44 roberto Exp roberto $ +** $Id: ltests.c,v 1.129 2002/07/09 14:58:28 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -413,7 +413,7 @@ static int newuserdata (lua_State *L) { static int pushuserdata (lua_State *L) { - lua_pushudataval(L, cast(void *, luaL_check_int(L, 1))); + lua_pushlightuserdata(L, cast(void *, luaL_check_int(L, 1))); return 1; } @@ -579,7 +579,7 @@ static int testC (lua_State *L) { lua_pushnumber(L, lua_isuserdata(L, getnum)); } else if EQ("isudataval") { - lua_pushnumber(L, lua_isudataval(L, getnum)); + lua_pushnumber(L, lua_islightuserdata(L, getnum)); } else if EQ("isnil") { lua_pushnumber(L, lua_isnil(L, getnum)); @@ -741,11 +741,12 @@ static void fim (void) { } -void luaB_opentests (lua_State *L) { +int luaB_opentests (lua_State *L) { *cast(int **, L) = &islocked; /* init lock */ lua_state = L; /* keep first state to be opened */ luaL_opennamedlib(L, "T", tests_funcs, 0); atexit(fim); + return 0; } #endif diff --git a/ltests.h b/ltests.h index 9a03d27a..821ce07c 100644 --- a/ltests.h +++ b/ltests.h @@ -1,5 +1,5 @@ /* -** $Id: ltests.h,v 1.13 2002/06/11 16:26:12 roberto Exp roberto $ +** $Id: ltests.h,v 1.14 2002/06/13 13:45:31 roberto Exp roberto $ ** Internal Header for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -47,16 +47,15 @@ extern int islocked; #define lua_unlock(L) lua_assert(--(**cast(int **, L)) == 0) -void luaB_opentests (lua_State *L); +int luaB_opentests (lua_State *L); -#define LUA_USERINIT(L) (luaB_opentests(L), openstdlibs(L)) +#define lua_userinit(L) (luaB_opentests(L) + openstdlibs(L)) /* change some sizes to give some bugs a chance */ #define LUAL_BUFFERSIZE 27 -#define ZBSIZE 29 #define MINSTRTABSIZE 2 #endif diff --git a/ltm.c b/ltm.c index 580936e1..d9a8dcac 100644 --- a/ltm.c +++ b/ltm.c @@ -1,5 +1,5 @@ /* -** $Id: ltm.c,v 1.96 2002/06/24 20:17:59 roberto Exp roberto $ +** $Id: ltm.c,v 1.97 2002/06/25 19:17:22 roberto Exp roberto $ ** Tag methods ** See Copyright Notice in lua.h */ @@ -19,7 +19,7 @@ const char *const luaT_typenames[] = { "nil", "number", "string", "boolean", "table", - "userdata", "userdata", "function" + "function", "userdata", "userdata" }; diff --git a/lua.h b/lua.h index 7bf7be0d..e7953e4c 100644 --- a/lua.h +++ b/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.145 2002/07/01 19:31:10 roberto Exp roberto $ +** $Id: lua.h,v 1.146 2002/07/09 14:58:28 roberto Exp roberto $ ** Lua - An Extensible Extension Language ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil ** http://www.lua.org mailto:info@lua.org @@ -70,9 +70,9 @@ typedef const char * (*lua_Chunkreader) (void *ud, size_t *size); #define LUA_TSTRING 2 #define LUA_TBOOLEAN 3 #define LUA_TTABLE 4 -#define LUA_TUSERDATA 5 -#define LUA_TUDATAVAL 6 -#define LUA_TFUNCTION 7 +#define LUA_TFUNCTION 5 +#define LUA_TUSERDATA 6 +#define LUA_TLIGHTUSERDATA 7 /* minimum Lua stack available to a C function */ @@ -158,7 +158,7 @@ LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...); LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); LUA_API void lua_pushboolean (lua_State *L, int b); -LUA_API void lua_pushudataval (lua_State *L, void *p); +LUA_API void lua_pushlightuserdata (lua_State *L, void *p); /* @@ -225,10 +225,10 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size); ** =============================================================== */ -#define lua_newpointerbox(L,u) \ +#define lua_boxpointer(L,u) \ (*(void **)(lua_newuserdata(L, sizeof(void *))) = (u)) -#define lua_getfrombox(L,i) (*(void **)(lua_touserdata(L, i))) +#define lua_unboxpointer(L,i) (*(void **)(lua_touserdata(L, i))) #define lua_pop(L,n) lua_settop(L, -(n)-1) @@ -241,8 +241,8 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size); #define lua_isfunction(L,n) (lua_type(L,n) == LUA_TFUNCTION) #define lua_istable(L,n) (lua_type(L,n) == LUA_TTABLE) -#define lua_isuserdata(L,n) (lua_type(L,n) == LUA_TUSERDATA) -#define lua_isudataval(L,n) (lua_type(L,n) == LUA_TUDATAVAL) +#define lua_isuserdata(L,n) (lua_type(L,n) >= LUA_TUSERDATA) +#define lua_islightuserdata(L,n) (lua_type(L,n) == LUA_TLIGHTUSERDATA) #define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL) #define lua_isboolean(L,n) (lua_type(L,n) == LUA_TBOOLEAN) #define lua_isnone(L,n) (lua_type(L,n) == LUA_TNONE) diff --git a/lvm.c b/lvm.c index 8dcd83eb..d966a179 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 1.246 2002/07/08 20:22:08 roberto Exp roberto $ +** $Id: lvm.c,v 1.247 2002/07/16 14:26:56 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -263,7 +263,7 @@ int luaV_equalval (lua_State *L, const TObject *t1, const TObject *t2) { case LUA_TNUMBER: return nvalue(t1) == nvalue(t2); case LUA_TSTRING: return tsvalue(t1) == tsvalue(t2); case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ - case LUA_TUDATAVAL: return pvalue(t1) == pvalue(t2); + case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); case LUA_TFUNCTION: return clvalue(t1) == clvalue(t2); case LUA_TUSERDATA: if (uvalue(t1) == uvalue(t2)) return 1;