Browse Source

new constant LUA_NOOBJECT.
'lua_createtable' does not have parameters.
'lua_copystring' now is a macro

Roberto Ierusalimschy 31 years ago
parent
commit
068d1cd1ee
2 changed files with 18 additions and 25 deletions
  1. 6 3
      lua.h
  2. 12 22
      opcode.c

+ 6 - 3
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.11 1994/11/18 19:46:21 roberto Stab roberto $
+** $Id: lua.h,v 3.12 1994/12/13 15:54:21 roberto Exp roberto $
 */
 
 
@@ -25,6 +25,8 @@ typedef enum
 
 /* Public Part */
 
+#define LUA_NOOBJECT  0
+
 typedef void (*lua_CFunction) (void);
 typedef unsigned int lua_Object;
 
@@ -44,7 +46,6 @@ lua_Object     lua_getparam 		(int number);
 
 float          lua_getnumber 		(lua_Object object);
 char          *lua_getstring 		(lua_Object object);
-char 	      *lua_copystring 		(lua_Object object);
 lua_CFunction  lua_getcfunction 	(lua_Object object);
 void          *lua_getuserdata  	(lua_Object object);
 
@@ -68,7 +69,7 @@ int	       lua_lock			(void);
 lua_Object     lua_getlocked		(int ref);
 void	       lua_unlock		(int ref);
 
-lua_Object     lua_createtable		(int initSize);
+lua_Object     lua_createtable		(void);
 
 
 /* some useful macros */
@@ -93,4 +94,6 @@ lua_Object     lua_createtable		(int initSize);
 #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript())
 #define lua_getfield(o,f)   (lua_pushobject(o), lua_pushstring(f), lua_getsubscript())
 
+#define lua_copystring(o) (strdup(lua_getstring(o)))
+
 #endif

+ 12 - 22
opcode.c

@@ -3,7 +3,7 @@
 ** TecCGraf - PUC-Rio
 */
 
-char *rcs_opcode="$Id: opcode.c,v 3.24 1994/12/06 14:27:18 roberto Exp roberto $";
+char *rcs_opcode="$Id: opcode.c,v 3.25 1994/12/13 15:54:21 roberto Exp roberto $";
 
 #include <setjmp.h>
 #include <stdio.h>
@@ -448,7 +448,7 @@ lua_Object lua_getsubscript (void)
   if (status == 0)
     return (Ref(top-1));
   else
-    return 0;
+    return LUA_NOOBJECT;
 }
 
 
@@ -495,10 +495,10 @@ int lua_storesubscript (void)
 /*
 ** API: creates a new table
 */
-lua_Object lua_createtable (int initSize)
+lua_Object lua_createtable (void)
 {
   adjustC(0);
-  avalue(top) = lua_createarray(initSize);
+  avalue(top) = lua_createarray(0);
   tag(top) = LUA_T_ARRAY;
   top++;
   CBase++;  /* incorporate object in the stack */
@@ -506,12 +506,12 @@ lua_Object lua_createtable (int initSize)
 }
 
 /*
-** Get a parameter, returning the object handle or 0 on error.
+** Get a parameter, returning the object handle or LUA_NOOBJECT on error.
 ** 'number' must be 1 to get the first parameter.
 */
 lua_Object lua_getparam (int number)
 {
- if (number <= 0 || number > CnResults) return 0;
+ if (number <= 0 || number > CnResults) return LUA_NOOBJECT;
  /* Ref(stack+(CBase-CnResults+number-1)) ==
     stack+(CBase-CnResults+number-1)-stack+1 == */
  return CBase-CnResults+number;
@@ -522,7 +522,7 @@ lua_Object lua_getparam (int number)
 */
 real lua_getnumber (lua_Object object)
 {
- if (object == 0 || tag(Address(object)) == LUA_T_NIL) return 0.0;
+ if (object == LUA_NOOBJECT || tag(Address(object)) == LUA_T_NIL) return 0.0;
  if (tonumber (Address(object))) return 0.0;
  else                   return (nvalue(Address(object)));
 }
@@ -532,28 +532,18 @@ real lua_getnumber (lua_Object object)
 */
 char *lua_getstring (lua_Object object)
 {
- if (object == 0 || tag(Address(object)) == LUA_T_NIL) return NULL;
+ if (object == LUA_NOOBJECT || tag(Address(object)) == LUA_T_NIL) return NULL;
  if (tostring (Address(object))) return NULL;
  else return (svalue(Address(object)));
 }
 
-/*
-** Given an object handle, return a copy of its string. On error, return NULL.
-*/
-char *lua_copystring (lua_Object object)
-{
- if (object == 0 || tag(Address(object)) == LUA_T_NIL) return NULL;
- if (tostring (Address(object))) return NULL;
- else return (strdup(svalue(Address(object))));
-}
-
 /*
 ** Given an object handle, return its cfuntion pointer. On error, return NULL.
 */
 lua_CFunction lua_getcfunction (lua_Object object)
 {
- if (object == 0) return NULL;
- if (tag(Address(object)) != LUA_T_CFUNCTION) return NULL;
+ if (object == LUA_NOOBJECT || tag(Address(object)) != LUA_T_CFUNCTION)
+   return NULL;
  else return (fvalue(Address(object)));
 }
 
@@ -562,8 +552,8 @@ lua_CFunction lua_getcfunction (lua_Object object)
 */
 void *lua_getuserdata (lua_Object object)
 {
- if (object == 0) return NULL;
- if (tag(Address(object)) < LUA_T_USERDATA) return NULL;
+ if (object == LUA_NOOBJECT || tag(Address(object)) < LUA_T_USERDATA)
+   return NULL;
  else return (uvalue(Address(object)));
 }