aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-02-20 12:51:14 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-02-20 12:51:14 -0300
commit6769f3481701a17d15d513c5b875999d38d81877 (patch)
treeaedeeba87f17a4633750f5d9fdd5d7d001326293
parent0b110f7922b2e5c066f3b10f50e4d1079ccd7f93 (diff)
downloadlua-6769f3481701a17d15d513c5b875999d38d81877.tar.gz
lua-6769f3481701a17d15d513c5b875999d38d81877.tar.bz2
lua-6769f3481701a17d15d513c5b875999d38d81877.zip
lua_Type is private (preparation for tags)
-rw-r--r--lua.h35
-rw-r--r--opcode.c45
-rw-r--r--opcode.h16
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 @@
2** LUA - Linguagem para Usuarios de Aplicacao 2** LUA - Linguagem para Usuarios de Aplicacao
3** Grupo de Tecnologia em Computacao Grafica 3** Grupo de Tecnologia em Computacao Grafica
4** TeCGraf - PUC-Rio 4** TeCGraf - PUC-Rio
5** $Id: lua.h,v 3.32 1996/11/20 13:49:32 roberto Exp roberto $ 5** $Id: lua.h,v 3.33 1997/02/11 11:40:01 roberto Exp roberto $
6*/ 6*/
7 7
8 8
@@ -14,25 +14,6 @@
14#define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo" 14#define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
15 15
16 16
17/* Private Part */
18
19typedef enum
20{
21 LUA_T_NIL = -1,
22 LUA_T_NUMBER = -2,
23 LUA_T_STRING = -3,
24 LUA_T_ARRAY = -4,
25 LUA_T_FUNCTION = -5,
26 LUA_T_CFUNCTION= -6,
27 LUA_T_MARK = -7,
28 LUA_T_CMARK = -8,
29 LUA_T_LINE = -9,
30 LUA_T_USERDATA = 0
31} lua_Type;
32
33
34/* Public Part */
35
36#define LUA_NOOBJECT 0 17#define LUA_NOOBJECT 0
37 18
38typedef void (*lua_CFunction) (void); 19typedef void (*lua_CFunction) (void);
@@ -52,10 +33,10 @@ void lua_endblock (void);
52lua_Object lua_getparam (int number); 33lua_Object lua_getparam (int number);
53#define lua_getresult(_) lua_getparam(_) 34#define lua_getresult(_) lua_getparam(_)
54 35
55#define lua_isnil(_) (lua_type(_)==LUA_T_NIL) 36int lua_isnil (lua_Object object);
56#define lua_istable(_) (lua_type(_)==LUA_T_ARRAY) 37int lua_istable (lua_Object object);
57#define lua_isuserdata(_) (lua_type(_)>=LUA_T_USERDATA) 38int lua_isuserdata (lua_Object object);
58#define lua_iscfunction(_) (lua_type(_)==LUA_T_CFUNCTION) 39int lua_iscfunction (lua_Object object);
59int lua_isnumber (lua_Object object); 40int lua_isnumber (lua_Object object);
60int lua_isstring (lua_Object object); 41int lua_isstring (lua_Object object);
61int lua_isfunction (lua_Object object); 42int lua_isfunction (lua_Object object);
@@ -65,7 +46,6 @@ char *lua_getstring (lua_Object object);
65lua_CFunction lua_getcfunction (lua_Object object); 46lua_CFunction lua_getcfunction (lua_Object object);
66void *lua_getbinarydata (lua_Object object); 47void *lua_getbinarydata (lua_Object object);
67int lua_getbindatasize (lua_Object object); 48int lua_getbindatasize (lua_Object object);
68void *lua_getuserdata (lua_Object object);
69 49
70void lua_pushnil (void); 50void lua_pushnil (void);
71void lua_pushnumber (float n); 51void lua_pushnumber (float n);
@@ -98,11 +78,14 @@ lua_Object lua_createtable (void);
98 78
99#define lua_register(n,f) (lua_pushcfunction(f), lua_storeglobal(n)) 79#define lua_register(n,f) (lua_pushcfunction(f), lua_storeglobal(n))
100 80
101#define lua_pushuserdata(u) lua_pushusertag(u, LUA_T_USERDATA) 81#define lua_pushuserdata(u) lua_pushusertag(u, 0)
82
102 83
103 84
104/* for compatibility with old versions. Avoid using these macros */ 85/* for compatibility with old versions. Avoid using these macros */
105 86
87#define lua_getuserdata(o) (*(void **)lua_getbinarydata(o))
88
106#define lua_lockobject(o) lua_refobject(o,1) 89#define lua_lockobject(o) lua_refobject(o,1)
107#define lua_lock() lua_ref(1) 90#define lua_lock() lua_ref(1)
108#define lua_getlocked lua_getref 91#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 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 3.79 1997/01/31 14:27:11 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 3.80 1997/02/11 11:35:05 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -671,20 +671,41 @@ lua_Object lua_getparam (int number)
671 return CLS_current.base-CLS_current.num+number; 671 return CLS_current.base-CLS_current.num+number;
672} 672}
673 673
674int lua_isnumber (lua_Object object) 674int lua_isnil (lua_Object o)
675{ 675{
676 return (object != LUA_NOOBJECT) && (tonumber(Address(object)) == 0); 676 return (o!= LUA_NOOBJECT) && (tag(Address(o)) == LUA_T_NIL);
677} 677}
678 678
679int lua_isstring (lua_Object object) 679int lua_istable (lua_Object o)
680{ 680{
681 int t = lua_type(object); 681 return (o!= LUA_NOOBJECT) && (tag(Address(o)) == LUA_T_ARRAY);
682}
683
684int lua_isuserdata (lua_Object o)
685{
686 return (o!= LUA_NOOBJECT) && (tag(Address(o)) == LUA_T_USERDATA);
687}
688
689int lua_iscfunction (lua_Object o)
690{
691 int t = lua_type(o);
692 return (t == LUA_T_CMARK) || (t == LUA_T_CFUNCTION);
693}
694
695int lua_isnumber (lua_Object o)
696{
697 return (o!= LUA_NOOBJECT) && (tonumber(Address(o)) == 0);
698}
699
700int lua_isstring (lua_Object o)
701{
702 int t = lua_type(o);
682 return (t == LUA_T_STRING) || (t == LUA_T_NUMBER); 703 return (t == LUA_T_STRING) || (t == LUA_T_NUMBER);
683} 704}
684 705
685int lua_isfunction (lua_Object object) 706int lua_isfunction (lua_Object o)
686{ 707{
687 int t = lua_type(object); 708 int t = lua_type(o);
688 return (t == LUA_T_FUNCTION) || (t == LUA_T_CFUNCTION) || 709 return (t == LUA_T_FUNCTION) || (t == LUA_T_CFUNCTION) ||
689 (t == LUA_T_MARK) || (t == LUA_T_CMARK); 710 (t == LUA_T_MARK) || (t == LUA_T_CMARK);
690} 711}
@@ -734,14 +755,6 @@ lua_CFunction lua_getcfunction (lua_Object object)
734 else return (fvalue(Address(object))); 755 else return (fvalue(Address(object)));
735} 756}
736 757
737/*
738** Given an object handle, return its user data. On error, return NULL.
739*/
740void *lua_getuserdata (lua_Object object)
741{
742 return *(void **)lua_getbinarydata(object);
743}
744
745 758
746lua_Object lua_getref (int ref) 759lua_Object lua_getref (int ref)
747{ 760{
@@ -888,7 +901,7 @@ int lua_type (lua_Object o)
888 lua_Type t = tag(Address(o)); 901 lua_Type t = tag(Address(o));
889 if (t == LUA_T_USERDATA) 902 if (t == LUA_T_USERDATA)
890 return (Address(o))->value.ts->tag; 903 return (Address(o))->value.ts->tag;
891 else return tag(Address(o)); 904 else return t;
892 } 905 }
893} 906}
894 907
diff --git a/opcode.h b/opcode.h
index dde9c11d..c3942159 100644
--- a/opcode.h
+++ b/opcode.h
@@ -1,6 +1,6 @@
1/* 1/*
2** TeCGraf - PUC-Rio 2** TeCGraf - PUC-Rio
3** $Id: opcode.h,v 3.24 1996/11/01 12:46:59 roberto Exp roberto $ 3** $Id: opcode.h,v 3.25 1997/02/11 11:35:05 roberto Exp roberto $
4*/ 4*/
5 5
6#ifndef opcode_h 6#ifndef opcode_h
@@ -14,6 +14,20 @@
14 14
15#define FIELDS_PER_FLUSH 40 15#define FIELDS_PER_FLUSH 40
16 16
17typedef enum
18{
19 LUA_T_NIL = -1,
20 LUA_T_NUMBER = -2,
21 LUA_T_STRING = -3,
22 LUA_T_ARRAY = -4, /* array==table */
23 LUA_T_FUNCTION = -5,
24 LUA_T_CFUNCTION= -6,
25 LUA_T_MARK = -7,
26 LUA_T_CMARK = -8,
27 LUA_T_LINE = -9,
28 LUA_T_USERDATA = 0
29} lua_Type;
30
17 31
18typedef enum { 32typedef enum {
19/* name parm before after side effect 33/* name parm before after side effect