summaryrefslogtreecommitdiff
path: root/lobject.h
diff options
context:
space:
mode:
Diffstat (limited to 'lobject.h')
-rw-r--r--lobject.h39
1 files changed, 30 insertions, 9 deletions
diff --git a/lobject.h b/lobject.h
index ce8e9e26..f093b3cb 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 2.36 2010/03/26 20:58:11 roberto Exp roberto $ 2** $Id: lobject.h,v 2.37 2010/04/12 16:07:06 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*/
@@ -25,6 +25,12 @@
25 25
26 26
27/* 27/*
28** Variant tag for C-function pointers (negative to be considered
29** non collectable by 'iscollectable')
30*/
31#define LUA_TCFP (~0x0F | LUA_TFUNCTION)
32
33/*
28** Union of all collectable objects 34** Union of all collectable objects
29*/ 35*/
30typedef union GCObject GCObject; 36typedef union GCObject GCObject;
@@ -54,6 +60,7 @@ typedef union {
54 void *p; 60 void *p;
55 lua_Number n; 61 lua_Number n;
56 int b; 62 int b;
63 lua_CFunction f;
57} Value; 64} Value;
58 65
59 66
@@ -73,12 +80,26 @@ typedef struct lua_TValue {
73#define NILCONSTANT {NULL}, LUA_TNIL 80#define NILCONSTANT {NULL}, LUA_TNIL
74 81
75 82
83/*
84** type tag of a TValue
85*/
86#define ttype(o) ((o)->tt_)
87
88
89/*
90** type tag of a TValue with no variants
91*/
92#define ttypenv(o) (ttype(o) & 0x0F)
93
94
76/* Macros to test type */ 95/* Macros to test type */
77#define ttisnil(o) (ttype(o) == LUA_TNIL) 96#define ttisnil(o) (ttype(o) == LUA_TNIL)
78#define ttisnumber(o) (ttype(o) == LUA_TNUMBER) 97#define ttisnumber(o) (ttype(o) == LUA_TNUMBER)
79#define ttisstring(o) (ttype(o) == LUA_TSTRING) 98#define ttisstring(o) (ttype(o) == LUA_TSTRING)
80#define ttistable(o) (ttype(o) == LUA_TTABLE) 99#define ttistable(o) (ttype(o) == LUA_TTABLE)
81#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) 100#define ttisfunction(o) (ttypenv(o) == LUA_TFUNCTION)
101#define ttisclosure(o) (ttype(o) == LUA_TFUNCTION)
102#define ttiscfp(o) (ttype(o) == LUA_TCFP)
82#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) 103#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN)
83#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) 104#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA)
84#define ttisthread(o) (ttype(o) == LUA_TTHREAD) 105#define ttisthread(o) (ttype(o) == LUA_TTHREAD)
@@ -86,7 +107,6 @@ typedef struct lua_TValue {
86#define ttisdeadkey(o) (ttype(o) == LUA_TDEADKEY) 107#define ttisdeadkey(o) (ttype(o) == LUA_TDEADKEY)
87 108
88/* Macros to access values */ 109/* Macros to access values */
89#define ttype(o) ((o)->tt_)
90#define gcvalue(o) check_exp(iscollectable(o), (o)->value_.gc) 110#define gcvalue(o) check_exp(iscollectable(o), (o)->value_.gc)
91#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value_.p) 111#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value_.p)
92#define nvalue(o) check_exp(ttisnumber(o), (o)->value_.n) 112#define nvalue(o) check_exp(ttisnumber(o), (o)->value_.n)
@@ -94,16 +114,15 @@ typedef struct lua_TValue {
94#define tsvalue(o) (&rawtsvalue(o)->tsv) 114#define tsvalue(o) (&rawtsvalue(o)->tsv)
95#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value_.gc->u) 115#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value_.gc->u)
96#define uvalue(o) (&rawuvalue(o)->uv) 116#define uvalue(o) (&rawuvalue(o)->uv)
97#define clvalue(o) check_exp(ttisfunction(o), &(o)->value_.gc->cl) 117#define clvalue(o) check_exp(ttisclosure(o), &(o)->value_.gc->cl)
118#define fvalue(o) check_exp(ttiscfp(o), (o)->value_.f)
98#define hvalue(o) check_exp(ttistable(o), &(o)->value_.gc->h) 119#define hvalue(o) check_exp(ttistable(o), &(o)->value_.gc->h)
99#define bvalue(o) check_exp(ttisboolean(o), (o)->value_.b) 120#define bvalue(o) check_exp(ttisboolean(o), (o)->value_.b)
100#define thvalue(o) check_exp(ttisthread(o), &(o)->value_.gc->th) 121#define thvalue(o) check_exp(ttisthread(o), &(o)->value_.gc->th)
101 122
102#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) 123#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
103 124
104/* 125
105** for internal debug only
106*/
107#define iscollectable(o) (ttype(o) >= LUA_TSTRING) 126#define iscollectable(o) (ttype(o) >= LUA_TSTRING)
108 127
109#define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt) 128#define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt)
@@ -120,6 +139,9 @@ typedef struct lua_TValue {
120#define setnvalue(obj,x) \ 139#define setnvalue(obj,x) \
121 { TValue *i_o=(obj); i_o->value_.n=(x); i_o->tt_=LUA_TNUMBER; } 140 { TValue *i_o=(obj); i_o->value_.n=(x); i_o->tt_=LUA_TNUMBER; }
122 141
142#define setfvalue(obj,x) \
143 { TValue *i_o=(obj); i_o->value_.f=(x); i_o->tt_=LUA_TCFP; }
144
123#define changenvalue(obj,x) \ 145#define changenvalue(obj,x) \
124 ( lua_assert((obj)->tt_==LUA_TNUMBER), (obj)->value_.n=(x) ) 146 ( lua_assert((obj)->tt_==LUA_TNUMBER), (obj)->value_.n=(x) )
125 147
@@ -313,8 +335,7 @@ typedef union Closure {
313} Closure; 335} Closure;
314 336
315 337
316#define iscfunction(o) (ttisfunction(o) && clvalue(o)->c.isC) 338#define isLfunction(o) (ttisclosure(o) && !clvalue(o)->c.isC)
317#define isLfunction(o) (ttisfunction(o) && !clvalue(o)->c.isC)
318 339
319#define getproto(o) (clvalue(o)->l.p) 340#define getproto(o) (clvalue(o)->l.p)
320 341