Browse Source

new names for light userdata operations

Roberto Ierusalimschy 23 năm trước cách đây
mục cha
commit
79c8edb6c4
13 tập tin đã thay đổi với 47 bổ sung44 xóa
  1. 6 3
      lapi.c
  2. 5 5
      lbaselib.c
  3. 4 4
      ldblib.c
  4. 2 2
      lgc.c
  5. 2 2
      liolib.c
  6. 2 2
      lobject.c
  7. 3 3
      lobject.h
  8. 2 2
      ltable.c
  9. 5 4
      ltests.c
  10. 3 4
      ltests.h
  11. 2 2
      ltm.c
  12. 9 9
      lua.h
  13. 2 2
      lvm.c

+ 6 - 3
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);

+ 5 - 5
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);

+ 4 - 4
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));

+ 2 - 2
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);
 

+ 2 - 2
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);

+ 2 - 2
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);

+ 3 - 3
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); }

+ 2 - 2
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));

+ 5 - 4
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

+ 3 - 4
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

+ 2 - 2
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"
 };
 
 

+ 9 - 9
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:[email protected]
@@ -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)

+ 2 - 2
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;