From 6769f3481701a17d15d513c5b875999d38d81877 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 20 Feb 1997 12:51:14 -0300 Subject: lua_Type is private (preparation for tags) --- lua.h | 35 +++++++++-------------------------- opcode.c | 45 +++++++++++++++++++++++++++++---------------- opcode.h | 16 +++++++++++++++- 3 files changed, 53 insertions(+), 43 deletions(-) diff --git a/lua.h b/lua.h index 459f87c0..e656134e 100644 --- a/lua.h +++ b/lua.h @@ -2,7 +2,7 @@ ** LUA - Linguagem para Usuarios de Aplicacao ** Grupo de Tecnologia em Computacao Grafica ** TeCGraf - PUC-Rio -** $Id: lua.h,v 3.32 1996/11/20 13:49:32 roberto Exp roberto $ +** $Id: lua.h,v 3.33 1997/02/11 11:40:01 roberto Exp roberto $ */ @@ -14,25 +14,6 @@ #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo" -/* Private Part */ - -typedef enum -{ - LUA_T_NIL = -1, - LUA_T_NUMBER = -2, - LUA_T_STRING = -3, - LUA_T_ARRAY = -4, - LUA_T_FUNCTION = -5, - LUA_T_CFUNCTION= -6, - LUA_T_MARK = -7, - LUA_T_CMARK = -8, - LUA_T_LINE = -9, - LUA_T_USERDATA = 0 -} lua_Type; - - -/* Public Part */ - #define LUA_NOOBJECT 0 typedef void (*lua_CFunction) (void); @@ -52,10 +33,10 @@ void lua_endblock (void); lua_Object lua_getparam (int number); #define lua_getresult(_) lua_getparam(_) -#define lua_isnil(_) (lua_type(_)==LUA_T_NIL) -#define lua_istable(_) (lua_type(_)==LUA_T_ARRAY) -#define lua_isuserdata(_) (lua_type(_)>=LUA_T_USERDATA) -#define lua_iscfunction(_) (lua_type(_)==LUA_T_CFUNCTION) +int lua_isnil (lua_Object object); +int lua_istable (lua_Object object); +int lua_isuserdata (lua_Object object); +int lua_iscfunction (lua_Object object); int lua_isnumber (lua_Object object); int lua_isstring (lua_Object object); int lua_isfunction (lua_Object object); @@ -65,7 +46,6 @@ char *lua_getstring (lua_Object object); lua_CFunction lua_getcfunction (lua_Object object); void *lua_getbinarydata (lua_Object object); int lua_getbindatasize (lua_Object object); -void *lua_getuserdata (lua_Object object); void lua_pushnil (void); void lua_pushnumber (float n); @@ -98,11 +78,14 @@ lua_Object lua_createtable (void); #define lua_register(n,f) (lua_pushcfunction(f), lua_storeglobal(n)) -#define lua_pushuserdata(u) lua_pushusertag(u, LUA_T_USERDATA) +#define lua_pushuserdata(u) lua_pushusertag(u, 0) + /* for compatibility with old versions. Avoid using these macros */ +#define lua_getuserdata(o) (*(void **)lua_getbinarydata(o)) + #define lua_lockobject(o) lua_refobject(o,1) #define lua_lock() lua_ref(1) #define lua_getlocked lua_getref diff --git a/opcode.c b/opcode.c index 281cf1bb..c089dccb 100644 --- a/opcode.c +++ b/opcode.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 3.79 1997/01/31 14:27:11 roberto Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 3.80 1997/02/11 11:35:05 roberto Exp roberto $"; #include #include @@ -671,20 +671,41 @@ lua_Object lua_getparam (int number) return CLS_current.base-CLS_current.num+number; } -int lua_isnumber (lua_Object object) +int lua_isnil (lua_Object o) { - return (object != LUA_NOOBJECT) && (tonumber(Address(object)) == 0); + return (o!= LUA_NOOBJECT) && (tag(Address(o)) == LUA_T_NIL); } -int lua_isstring (lua_Object object) +int lua_istable (lua_Object o) { - int t = lua_type(object); + return (o!= LUA_NOOBJECT) && (tag(Address(o)) == LUA_T_ARRAY); +} + +int lua_isuserdata (lua_Object o) +{ + return (o!= LUA_NOOBJECT) && (tag(Address(o)) == LUA_T_USERDATA); +} + +int lua_iscfunction (lua_Object o) +{ + int t = lua_type(o); + return (t == LUA_T_CMARK) || (t == LUA_T_CFUNCTION); +} + +int lua_isnumber (lua_Object o) +{ + return (o!= LUA_NOOBJECT) && (tonumber(Address(o)) == 0); +} + +int lua_isstring (lua_Object o) +{ + int t = lua_type(o); return (t == LUA_T_STRING) || (t == LUA_T_NUMBER); } -int lua_isfunction (lua_Object object) +int lua_isfunction (lua_Object o) { - int t = lua_type(object); + int t = lua_type(o); return (t == LUA_T_FUNCTION) || (t == LUA_T_CFUNCTION) || (t == LUA_T_MARK) || (t == LUA_T_CMARK); } @@ -734,14 +755,6 @@ lua_CFunction lua_getcfunction (lua_Object object) else return (fvalue(Address(object))); } -/* -** Given an object handle, return its user data. On error, return NULL. -*/ -void *lua_getuserdata (lua_Object object) -{ - return *(void **)lua_getbinarydata(object); -} - lua_Object lua_getref (int ref) { @@ -888,7 +901,7 @@ int lua_type (lua_Object o) lua_Type t = tag(Address(o)); if (t == LUA_T_USERDATA) return (Address(o))->value.ts->tag; - else return tag(Address(o)); + else return t; } } diff --git a/opcode.h b/opcode.h index dde9c11d..c3942159 100644 --- a/opcode.h +++ b/opcode.h @@ -1,6 +1,6 @@ /* ** TeCGraf - PUC-Rio -** $Id: opcode.h,v 3.24 1996/11/01 12:46:59 roberto Exp roberto $ +** $Id: opcode.h,v 3.25 1997/02/11 11:35:05 roberto Exp roberto $ */ #ifndef opcode_h @@ -14,6 +14,20 @@ #define FIELDS_PER_FLUSH 40 +typedef enum +{ + LUA_T_NIL = -1, + LUA_T_NUMBER = -2, + LUA_T_STRING = -3, + LUA_T_ARRAY = -4, /* array==table */ + LUA_T_FUNCTION = -5, + LUA_T_CFUNCTION= -6, + LUA_T_MARK = -7, + LUA_T_CMARK = -8, + LUA_T_LINE = -9, + LUA_T_USERDATA = 0 +} lua_Type; + typedef enum { /* name parm before after side effect -- cgit v1.2.3-55-g6feb