diff options
Diffstat (limited to 'lobject.h')
| -rw-r--r-- | lobject.h | 44 |
1 files changed, 38 insertions, 6 deletions
| @@ -27,15 +27,20 @@ | |||
| 27 | #endif | 27 | #endif |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | /* tags for values visible from Lua == first user-created tag */ | 30 | /* tags for values visible from Lua */ |
| 31 | #define NUM_TAGS 6 | 31 | #define NUM_TAGS 6 |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | /* extra tag: used locally when moving an upvalue from the stack to the heap */ | ||
| 35 | #define LUA_TUPVAL 6 | ||
| 36 | |||
| 37 | |||
| 34 | typedef union { | 38 | typedef union { |
| 35 | union TString *ts; | 39 | union TString *ts; |
| 36 | union Udata *u; | 40 | union Udata *u; |
| 37 | struct Closure *cl; | 41 | struct Closure *cl; |
| 38 | struct Hash *h; | 42 | struct Hash *h; |
| 43 | struct UpVal *v; | ||
| 39 | lua_Number n; /* LUA_TNUMBER */ | 44 | lua_Number n; /* LUA_TNUMBER */ |
| 40 | } Value; | 45 | } Value; |
| 41 | 46 | ||
| @@ -53,6 +58,7 @@ typedef struct lua_TObject { | |||
| 53 | #define uvalue(o) ((o)->value.u) | 58 | #define uvalue(o) ((o)->value.u) |
| 54 | #define clvalue(o) ((o)->value.cl) | 59 | #define clvalue(o) ((o)->value.cl) |
| 55 | #define hvalue(o) ((o)->value.h) | 60 | #define hvalue(o) ((o)->value.h) |
| 61 | #define vvalue(o) ((o)->value.v) | ||
| 56 | 62 | ||
| 57 | 63 | ||
| 58 | /* Macros to set values */ | 64 | /* Macros to set values */ |
| @@ -75,6 +81,9 @@ typedef struct lua_TObject { | |||
| 75 | 81 | ||
| 76 | #define setnilvalue(obj) ((obj)->tt=LUA_TNIL) | 82 | #define setnilvalue(obj) ((obj)->tt=LUA_TNIL) |
| 77 | 83 | ||
| 84 | #define setupvalue(obj,x) \ | ||
| 85 | { TObject *_o=(obj); _o->tt=LUA_TUPVAL; _o->value.v=(x); } | ||
| 86 | |||
| 78 | #define setobj(obj1,obj2) \ | 87 | #define setobj(obj1,obj2) \ |
| 79 | { TObject *o1=(obj1); const TObject *o2=(obj2); \ | 88 | { TObject *o1=(obj1); const TObject *o2=(obj2); \ |
| 80 | o1->tt=o2->tt; o1->value = o2->value; } | 89 | o1->tt=o2->tt; o1->value = o2->value; } |
| @@ -154,25 +163,48 @@ typedef struct LocVar { | |||
| 154 | } LocVar; | 163 | } LocVar; |
| 155 | 164 | ||
| 156 | 165 | ||
| 166 | |||
| 167 | /* | ||
| 168 | ** Upvalues in the heap | ||
| 169 | */ | ||
| 170 | typedef struct UpVal { | ||
| 171 | TObject val; | ||
| 172 | struct UpVal *next; | ||
| 173 | int marked; | ||
| 174 | } UpVal; | ||
| 175 | |||
| 176 | |||
| 157 | /* | 177 | /* |
| 158 | ** Closures | 178 | ** Closures |
| 159 | */ | 179 | */ |
| 160 | typedef struct Closure { | 180 | typedef struct Closure { |
| 161 | int isC; /* 0 for Lua functions, 1 for C functions */ | 181 | int isC; /* 0 for Lua functions, 1 for C functions */ |
| 162 | int nupvalues; | 182 | int nupvalues; |
| 163 | union { | ||
| 164 | lua_CFunction c; /* C functions */ | ||
| 165 | struct Proto *l; /* Lua functions */ | ||
| 166 | } f; | ||
| 167 | struct Closure *next; | 183 | struct Closure *next; |
| 168 | struct Closure *mark; /* marked closures (point to itself when not marked) */ | 184 | struct Closure *mark; /* marked closures (point to itself when not marked) */ |
| 169 | TObject upvalue[1]; | 185 | union { |
| 186 | struct { /* C functions */ | ||
| 187 | lua_CFunction f; | ||
| 188 | TObject upvalue[1]; | ||
| 189 | } c; | ||
| 190 | struct { /* Lua functions */ | ||
| 191 | struct Proto *p; | ||
| 192 | ls_bitup isopen; /* bitmap: bit==1 when upvals point to the stack */ | ||
| 193 | TObject *upvals[1]; /* may point to the stack or to an UpVal */ | ||
| 194 | } l; | ||
| 195 | } u; | ||
| 170 | } Closure; | 196 | } Closure; |
| 171 | 197 | ||
| 172 | 198 | ||
| 173 | #define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->isC) | 199 | #define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->isC) |
| 174 | 200 | ||
| 175 | 201 | ||
| 202 | |||
| 203 | |||
| 204 | /* | ||
| 205 | ** Hash Tables | ||
| 206 | */ | ||
| 207 | |||
| 176 | typedef struct Node { | 208 | typedef struct Node { |
| 177 | struct Node *next; /* for chaining */ | 209 | struct Node *next; /* for chaining */ |
| 178 | TObject key; | 210 | TObject key; |
