new names for light userdata operations

This commit is contained in:
Roberto Ierusalimschy 2002-07-17 13:25:13 -03:00
parent e5146fb01f
commit 79c8edb6c4
13 changed files with 47 additions and 44 deletions

9
lapi.c
View File

@ -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 ** Lua API
** See Copyright Notice in lua.h ** 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; if (o == NULL) return NULL;
switch (ttype(o)) { switch (ttype(o)) {
case LUA_TUSERDATA: return (uvalue(o) + 1); case LUA_TUSERDATA: return (uvalue(o) + 1);
case LUA_TUDATAVAL: return pvalue(o); case LUA_TLIGHTUSERDATA: return pvalue(o);
default: return NULL; default: return NULL;
} }
} }
@ -318,6 +318,9 @@ LUA_API const void *lua_topointer (lua_State *L, int index) {
switch (ttype(o)) { switch (ttype(o)) {
case LUA_TTABLE: return hvalue(o); case LUA_TTABLE: return hvalue(o);
case LUA_TFUNCTION: return clvalue(o); case LUA_TFUNCTION: return clvalue(o);
case LUA_TUSERDATA:
case LUA_TLIGHTUSERDATA:
return lua_touserdata(L, index);
default: return NULL; 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); lua_lock(L);
setpvalue(L->top, p); setpvalue(L->top, p);
api_incr_top(L); api_incr_top(L);

View File

@ -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 ** Basic library
** See Copyright Notice in lua.h ** 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)); sprintf(buff, "function: %p", lua_topointer(L, 1));
break; break;
case LUA_TUSERDATA: case LUA_TUSERDATA:
case LUA_TUDATAVAL: case LUA_TLIGHTUSERDATA:
sprintf(buff, "userdata: %p", lua_touserdata(L, 1)); sprintf(buff, "userdata: %p", lua_touserdata(L, 1));
break; break;
case LUA_TNIL: case LUA_TNIL:
@ -484,7 +484,7 @@ static const luaL_reg base_funcs[] = {
static int luaB_resume (lua_State *L) { 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; int status;
lua_settop(L, 0); lua_settop(L, 0);
status = lua_resume(L, co); status = lua_resume(L, co);
@ -503,7 +503,7 @@ static int luaB_resume (lua_State *L) {
static int gc_coroutine (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); lua_closethread(L, co);
return 0; return 0;
} }
@ -526,7 +526,7 @@ static int luaB_coroutine (lua_State *L) {
lua_unref(L, ref); lua_unref(L, ref);
} }
lua_cobegin(NL, n-1); lua_cobegin(NL, n-1);
lua_newpointerbox(L, NL); lua_boxpointer(L, NL);
lua_pushliteral(L, "Coroutine"); lua_pushliteral(L, "Coroutine");
lua_rawget(L, LUA_REGISTRYINDEX); lua_rawget(L, LUA_REGISTRYINDEX);
lua_setmetatable(L, -2); lua_setmetatable(L, -2);

View File

@ -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 ** Interface from Lua to its debug API
** See Copyright Notice in lua.h ** 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 void hookf (lua_State *L, lua_Debug *ar) {
static const char *const hooknames[] = {"call", "return", "line", "count"}; 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); lua_rawget(L, LUA_REGISTRYINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
lua_pushstring(L, hooknames[(int)ar->event]); lua_pushstring(L, hooknames[(int)ar->event]);
@ -157,7 +157,7 @@ static int sethook (lua_State *L) {
luaL_check_type(L, 1, LUA_TFUNCTION); luaL_check_type(L, 1, LUA_TFUNCTION);
lua_sethook(L, hookf, makemask(smask, count)); lua_sethook(L, hookf, makemask(smask, count));
} }
lua_pushudataval(L, (void *)&KEY_HOOK); lua_pushlightuserdata(L, (void *)&KEY_HOOK);
lua_pushvalue(L, 1); lua_pushvalue(L, 1);
lua_rawset(L, LUA_REGISTRYINDEX); /* set new hook */ lua_rawset(L, LUA_REGISTRYINDEX); /* set new hook */
return 0; return 0;
@ -167,7 +167,7 @@ static int sethook (lua_State *L) {
static int gethook (lua_State *L) { static int gethook (lua_State *L) {
char buff[5]; char buff[5];
int mask = lua_gethookmask(L); 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_rawget(L, LUA_REGISTRYINDEX); /* get hook */
lua_pushstring(L, unmakemask(mask, buff)); lua_pushstring(L, unmakemask(mask, buff));
lua_pushnumber(L, lua_getmaskcount(mask)); lua_pushnumber(L, lua_getmaskcount(mask));

4
lgc.c
View File

@ -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 ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -58,7 +58,7 @@ typedef struct GCState {
#define ismarkable(o) (!((1 << ttype(o)) & \ #define ismarkable(o) (!((1 << ttype(o)) & \
((1 << LUA_TNIL) | (1 << LUA_TNUMBER) | \ ((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); static void reallymarkobject (GCState *st, TObject *o);

View File

@ -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 ** Standard I/O (and system) library
** See Copyright Notice in lua.h ** 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) { static void newfile (lua_State *L, FILE *f) {
lua_newpointerbox(L, f); lua_boxpointer(L, f);
lua_pushliteral(L, FILEHANDLE); lua_pushliteral(L, FILEHANDLE);
lua_rawget(L, LUA_REGISTRYINDEX); lua_rawget(L, LUA_REGISTRYINDEX);
lua_setmetatable(L, -2); lua_setmetatable(L, -2);

View File

@ -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 ** Some generic functions over Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -66,7 +66,7 @@ int luaO_rawequalObj (const TObject *t1, const TObject *t2) {
return tsvalue(t1) == tsvalue(t2); return tsvalue(t1) == tsvalue(t2);
case LUA_TBOOLEAN: case LUA_TBOOLEAN:
return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */
case LUA_TUDATAVAL: case LUA_TLIGHTUSERDATA:
return pvalue(t1) == pvalue(t2); return pvalue(t1) == pvalue(t2);
case LUA_TUSERDATA: case LUA_TUSERDATA:
return uvalue(t1) == uvalue(t2); return uvalue(t1) == uvalue(t2);

View File

@ -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 ** Type definitions for Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -35,7 +35,7 @@ typedef struct lua_TObject {
/* Macros to access values */ /* Macros to access values */
#define ttype(o) ((o)->tt) #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 nvalue(o) check_exp(ttype(o)==LUA_TNUMBER, (o)->value.n)
#define tsvalue(o) check_exp(ttype(o)==LUA_TSTRING, (o)->value.ts) #define tsvalue(o) check_exp(ttype(o)==LUA_TSTRING, (o)->value.ts)
#define uvalue(o) check_exp(ttype(o)==LUA_TUSERDATA, (o)->value.u) #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)) check_exp(ttype(obj)==LUA_TNUMBER, (obj)->value.n=(x))
#define setpvalue(obj,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) \ #define setbvalue(obj,x) \
{ TObject *i_o=(obj); i_o->tt=LUA_TBOOLEAN; i_o->value.b=(x); } { TObject *i_o=(obj); i_o->tt=LUA_TBOOLEAN; i_o->value.b=(x); }

View File

@ -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) ** Lua tables (hash)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -80,7 +80,7 @@ Node *luaH_mainposition (const Table *t, const TObject *key) {
return hashstr(t, tsvalue(key)); return hashstr(t, tsvalue(key));
case LUA_TBOOLEAN: case LUA_TBOOLEAN:
return hashboolean(t, bvalue(key)); return hashboolean(t, bvalue(key));
case LUA_TUDATAVAL: case LUA_TLIGHTUSERDATA:
return hashpointer(t, pvalue(key)); return hashpointer(t, pvalue(key));
case LUA_TUSERDATA: case LUA_TUSERDATA:
return hashpointer(t, uvalue(key)); return hashpointer(t, uvalue(key));

View File

@ -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 ** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -413,7 +413,7 @@ static int newuserdata (lua_State *L) {
static int pushuserdata (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; return 1;
} }
@ -579,7 +579,7 @@ static int testC (lua_State *L) {
lua_pushnumber(L, lua_isuserdata(L, getnum)); lua_pushnumber(L, lua_isuserdata(L, getnum));
} }
else if EQ("isudataval") { else if EQ("isudataval") {
lua_pushnumber(L, lua_isudataval(L, getnum)); lua_pushnumber(L, lua_islightuserdata(L, getnum));
} }
else if EQ("isnil") { else if EQ("isnil") {
lua_pushnumber(L, lua_isnil(L, getnum)); 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 */ *cast(int **, L) = &islocked; /* init lock */
lua_state = L; /* keep first state to be opened */ lua_state = L; /* keep first state to be opened */
luaL_opennamedlib(L, "T", tests_funcs, 0); luaL_opennamedlib(L, "T", tests_funcs, 0);
atexit(fim); atexit(fim);
return 0;
} }
#endif #endif

View File

@ -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 ** Internal Header for Debugging of the Lua Implementation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -47,16 +47,15 @@ extern int islocked;
#define lua_unlock(L) lua_assert(--(**cast(int **, L)) == 0) #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 */ /* change some sizes to give some bugs a chance */
#define LUAL_BUFFERSIZE 27 #define LUAL_BUFFERSIZE 27
#define ZBSIZE 29
#define MINSTRTABSIZE 2 #define MINSTRTABSIZE 2
#endif #endif

4
ltm.c
View File

@ -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 ** Tag methods
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -19,7 +19,7 @@
const char *const luaT_typenames[] = { const char *const luaT_typenames[] = {
"nil", "number", "string", "boolean", "table", "nil", "number", "string", "boolean", "table",
"userdata", "userdata", "function" "function", "userdata", "userdata"
}; };

18
lua.h
View File

@ -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 ** Lua - An Extensible Extension Language
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
** http://www.lua.org mailto:info@lua.org ** 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_TSTRING 2
#define LUA_TBOOLEAN 3 #define LUA_TBOOLEAN 3
#define LUA_TTABLE 4 #define LUA_TTABLE 4
#define LUA_TUSERDATA 5 #define LUA_TFUNCTION 5
#define LUA_TUDATAVAL 6 #define LUA_TUSERDATA 6
#define LUA_TFUNCTION 7 #define LUA_TLIGHTUSERDATA 7
/* minimum Lua stack available to a C function */ /* 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 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_pushcclosure (lua_State *L, lua_CFunction fn, int n);
LUA_API void lua_pushboolean (lua_State *L, int b); 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)) (*(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) #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_isfunction(L,n) (lua_type(L,n) == LUA_TFUNCTION)
#define lua_istable(L,n) (lua_type(L,n) == LUA_TTABLE) #define lua_istable(L,n) (lua_type(L,n) == LUA_TTABLE)
#define lua_isuserdata(L,n) (lua_type(L,n) == LUA_TUSERDATA) #define lua_isuserdata(L,n) (lua_type(L,n) >= LUA_TUSERDATA)
#define lua_isudataval(L,n) (lua_type(L,n) == LUA_TUDATAVAL) #define lua_islightuserdata(L,n) (lua_type(L,n) == LUA_TLIGHTUSERDATA)
#define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL) #define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL)
#define lua_isboolean(L,n) (lua_type(L,n) == LUA_TBOOLEAN) #define lua_isboolean(L,n) (lua_type(L,n) == LUA_TBOOLEAN)
#define lua_isnone(L,n) (lua_type(L,n) == LUA_TNONE) #define lua_isnone(L,n) (lua_type(L,n) == LUA_TNONE)

4
lvm.c
View File

@ -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 ** Lua virtual machine
** See Copyright Notice in lua.h ** 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_TNUMBER: return nvalue(t1) == nvalue(t2);
case LUA_TSTRING: return tsvalue(t1) == tsvalue(t2); case LUA_TSTRING: return tsvalue(t1) == tsvalue(t2);
case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ 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_TFUNCTION: return clvalue(t1) == clvalue(t2);
case LUA_TUSERDATA: case LUA_TUSERDATA:
if (uvalue(t1) == uvalue(t2)) return 1; if (uvalue(t1) == uvalue(t2)) return 1;