diff options
Diffstat (limited to 'lobject.h')
-rw-r--r-- | lobject.h | 59 |
1 files changed, 44 insertions, 15 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.84 2000/12/04 18:33:40 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.85 2000/12/28 12:55:41 roberto Exp roberto $ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -40,32 +40,61 @@ | |||
40 | 40 | ||
41 | 41 | ||
42 | /* check whether `t' is a mark */ | 42 | /* check whether `t' is a mark */ |
43 | #define is_T_MARK(t) ((t) == LUA_TMARK) | 43 | #define is_T_MARK(t) (ttype(t) == LUA_TMARK) |
44 | 44 | ||
45 | 45 | ||
46 | typedef union { | 46 | typedef union { |
47 | struct TString *ts; /* LUA_TSTRING, LUA_TUSERDATA */ | 47 | void *v; |
48 | struct Closure *cl; /* LUA_TFUNCTION */ | ||
49 | struct Hash *a; /* LUA_TTABLE */ | ||
50 | struct CallInfo *i; /* LUA_TLMARK */ | ||
51 | lua_Number n; /* LUA_TNUMBER */ | 48 | lua_Number n; /* LUA_TNUMBER */ |
52 | } Value; | 49 | } Value; |
53 | 50 | ||
54 | 51 | ||
52 | typedef struct lua_TObject { | ||
53 | int tt; | ||
54 | Value value; | ||
55 | } TObject; | ||
56 | |||
57 | |||
55 | /* Macros to access values */ | 58 | /* Macros to access values */ |
56 | #define ttype(o) ((o)->ttype) | 59 | #define ttype(o) ((o)->tt) |
57 | #define nvalue(o) ((o)->value.n) | 60 | #define nvalue(o) ((o)->value.n) |
58 | #define tsvalue(o) ((o)->value.ts) | 61 | #define tsvalue(o) ((struct TString *)(o)->value.v) |
59 | #define clvalue(o) ((o)->value.cl) | 62 | #define clvalue(o) ((struct Closure *)(o)->value.v) |
60 | #define hvalue(o) ((o)->value.a) | 63 | #define hvalue(o) ((struct Hash *)(o)->value.v) |
61 | #define infovalue(o) ((o)->value.i) | 64 | #define infovalue(o) ((struct CallInfo *)(o)->value.v) |
62 | #define svalue(o) (tsvalue(o)->str) | 65 | #define svalue(o) (tsvalue(o)->str) |
63 | 66 | ||
64 | 67 | ||
65 | typedef struct lua_TObject { | 68 | /* Macros to set values */ |
66 | int ttype; | 69 | #define setnvalue(obj,x) \ |
67 | Value value; | 70 | { TObject *o=(obj); o->tt=LUA_TNUMBER; o->value.n=(x); } |
68 | } TObject; | 71 | |
72 | #define setsvalue(obj,x) \ | ||
73 | { TObject *o=(obj); struct TString *v=(x); \ | ||
74 | o->tt=LUA_TSTRING; o->value.v=v; } | ||
75 | |||
76 | #define setuvalue(obj,x) \ | ||
77 | { TObject *o=(obj); struct TString *v=(x); \ | ||
78 | o->tt=LUA_TUSERDATA; o->value.v=v; } | ||
79 | |||
80 | #define setclvalue(obj,x) \ | ||
81 | { TObject *o=(obj); struct Closure *v=(x); \ | ||
82 | o->tt=LUA_TFUNCTION; o->value.v=v; } | ||
83 | |||
84 | #define sethvalue(obj,x) \ | ||
85 | { TObject *o=(obj); struct Hash *v=(x); \ | ||
86 | o->tt=LUA_TTABLE; o->value.v=v; } | ||
87 | |||
88 | #define setivalue(obj,x) \ | ||
89 | { TObject *o=(obj); struct CallInfo *v=(x); \ | ||
90 | o->tt=LUA_TMARK; o->value.v=v; } | ||
91 | |||
92 | #define setnilvalue(obj) { (obj)->tt=LUA_TNIL; } | ||
93 | |||
94 | #define setobj(obj1,obj2) \ | ||
95 | { TObject *o1=(obj1); const TObject *o2=(obj2); \ | ||
96 | o1->tt=o2->tt; o1->value = o2->value; } | ||
97 | |||
69 | 98 | ||
70 | 99 | ||
71 | /* | 100 | /* |