浏览代码

new API function 'lua_type'.

Roberto Ierusalimschy 26 年之前
父节点
当前提交
63ccf42397
共有 3 个文件被更改,包括 15 次插入14 次删除
  1. 4 1
      lapi.c
  2. 8 8
      lbuiltin.c
  3. 3 5
      lua.h

+ 4 - 1
lapi.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lapi.c,v 1.50 1999/09/21 16:10:13 roberto Exp roberto $
+** $Id: lapi.c,v 1.51 1999/10/04 17:51:04 roberto Exp roberto $
 ** Lua API
 ** Lua API
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -216,6 +216,9 @@ void lua_rawsetglobal (const char *name) {
 }
 }
 
 
 
 
+const char *lua_type (lua_Object o) {
+  return (o == LUA_NOOBJECT) ? "NOOBJECT" : luaO_typename(Address(o));
+}
 
 
 int lua_isnil (lua_Object o) {
 int lua_isnil (lua_Object o) {
   return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_NIL);
   return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_NIL);

+ 8 - 8
lbuiltin.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lbuiltin.c,v 1.63 1999/09/20 14:57:29 roberto Exp roberto $
+** $Id: lbuiltin.c,v 1.64 1999/10/04 17:51:04 roberto Exp roberto $
 ** Built-in functions
 ** Built-in functions
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -247,6 +247,13 @@ static void luaB_collectgarbage (void) {
   lua_pushnumber(lua_collectgarbage(luaL_opt_int(1, 0)));
   lua_pushnumber(lua_collectgarbage(luaL_opt_int(1, 0)));
 }
 }
 
 
+
+static void luaB_type (void) {
+  lua_Object o = luaL_nonnullarg(1);
+  lua_pushstring(lua_type(o));
+  lua_pushnumber(lua_tag(o));
+}
+
 /* }====================================================== */
 /* }====================================================== */
 
 
 
 
@@ -371,13 +378,6 @@ static void luaB_tostring (void) {
   lua_pushstring(buff);
   lua_pushstring(buff);
 }
 }
 
 
-
-static void luaB_type (void) {
-  lua_Object o = luaL_nonnullarg(1);
-  lua_pushstring(luaO_typename(luaA_Address(o)));
-  lua_pushnumber(lua_tag(o));
-}
-
 /* }====================================================== */
 /* }====================================================== */
 
 
 
 

+ 3 - 5
lua.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lua.h,v 1.34 1999/08/16 20:52:00 roberto Exp roberto $
+** $Id: lua.h,v 1.35 1999/09/29 12:56:22 roberto Exp roberto $
 ** Lua - An Extensible Extension Language
 ** Lua - An Extensible Extension Language
 ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
 ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
 ** e-mail: [email protected]
 ** e-mail: [email protected]
@@ -58,6 +58,8 @@ lua_Object     lua_lua2C 		(int number);
 #define	       lua_getparam(_)		lua_lua2C(_)
 #define	       lua_getparam(_)		lua_lua2C(_)
 #define	       lua_getresult(_)		lua_lua2C(_)
 #define	       lua_getresult(_)		lua_lua2C(_)
 
 
+const char    *lua_type			(lua_Object object);
+
 int            lua_isnil                (lua_Object object);
 int            lua_isnil                (lua_Object object);
 int            lua_istable              (lua_Object object);
 int            lua_istable              (lua_Object object);
 int            lua_isuserdata           (lua_Object object);
 int            lua_isuserdata           (lua_Object object);
@@ -136,10 +138,8 @@ lua_Object     lua_seterrormethod (void);  /* In: new method */
 #ifdef LUA_COMPAT2_5
 #ifdef LUA_COMPAT2_5
 
 
 
 
-lua_Object     lua_setfallback		(char *event, lua_CFunction fallback);
 
 
 #define lua_storeglobal		lua_setglobal
 #define lua_storeglobal		lua_setglobal
-#define lua_type		lua_tag
 
 
 #define lua_lockobject(o)  lua_refobject(o,1)
 #define lua_lockobject(o)  lua_refobject(o,1)
 #define	lua_lock() lua_ref(1)
 #define	lua_lock() lua_ref(1)
@@ -152,8 +152,6 @@ lua_Object     lua_setfallback		(char *event, lua_CFunction fallback);
 #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_gettable())
 #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_gettable())
 #define lua_getfield(o,f)   (lua_pushobject(o), lua_pushstring(f), lua_gettable())
 #define lua_getfield(o,f)   (lua_pushobject(o), lua_pushstring(f), lua_gettable())
 
 
-#define lua_copystring(o) (strdup(lua_getstring(o)))
-
 #define lua_getsubscript  lua_gettable
 #define lua_getsubscript  lua_gettable
 #define lua_storesubscript  lua_settable
 #define lua_storesubscript  lua_settable