diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-05 09:14:08 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-05 09:14:08 -0300 |
| commit | 001f2bdd0e2f8803889c1b5164b57a51e44aef5b (patch) | |
| tree | d200cf4d708be3c61e64640c45b47050c9c6a375 /lobject.h | |
| parent | cd2ddaded97f7f2b2af02cecfd165cf70e6f83f4 (diff) | |
| download | lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.gz lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.bz2 lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.zip | |
new definition for types-tags
Diffstat (limited to 'lobject.h')
| -rw-r--r-- | lobject.h | 55 |
1 files changed, 21 insertions, 34 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 1.77 2000/09/29 12:42:13 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.78 2000/10/02 20:10:55 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 | */ |
| @@ -31,41 +31,24 @@ | |||
| 31 | #endif | 31 | #endif |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | /* | 34 | /* mark for closures active in the stack */ |
| 35 | ** Lua TYPES | 35 | #define LUA_TMARK 6 |
| 36 | ** WARNING: if you change the order of this enumeration, | ||
| 37 | ** grep "ORDER LUA_T" | ||
| 38 | */ | ||
| 39 | typedef enum { | ||
| 40 | TAG_USERDATA = 0, /* default tag for userdata */ | ||
| 41 | TAG_NUMBER, /* fixed tag for numbers */ | ||
| 42 | TAG_STRING, /* fixed tag for strings */ | ||
| 43 | TAG_TABLE, /* default tag for tables */ | ||
| 44 | TAG_LCLOSURE, /* fixed tag for Lua closures */ | ||
| 45 | TAG_CCLOSURE, /* fixed tag for C closures */ | ||
| 46 | TAG_NIL, /* last "pre-defined" tag */ | ||
| 47 | |||
| 48 | TAG_LMARK, /* mark for Lua closures */ | ||
| 49 | TAG_CMARK /* mark for C closures */ | ||
| 50 | 36 | ||
| 51 | } lua_Tag; | ||
| 52 | 37 | ||
| 53 | /* tags for values visible from Lua == first user-created tag */ | 38 | /* tags for values visible from Lua == first user-created tag */ |
| 54 | #define NUM_TAGS 7 | 39 | #define NUM_TAGS 6 |
| 55 | 40 | ||
| 56 | 41 | ||
| 57 | /* | 42 | /* check whether `t' is a mark */ |
| 58 | ** check whether `t' is a mark | 43 | #define is_T_MARK(t) ((t) == LUA_TMARK) |
| 59 | */ | ||
| 60 | #define is_T_MARK(t) ((t) == TAG_LMARK || (t) == TAG_CMARK) | ||
| 61 | 44 | ||
| 62 | 45 | ||
| 63 | typedef union { | 46 | typedef union { |
| 64 | struct TString *ts; /* TAG_STRING, TAG_USERDATA */ | 47 | struct TString *ts; /* LUA_TSTRING, LUA_TUSERDATA */ |
| 65 | struct Closure *cl; /* TAG_[CL]CLOSURE, TAG_CMARK */ | 48 | struct Closure *cl; /* LUA_TFUNCTION */ |
| 66 | struct Hash *a; /* TAG_TABLE */ | 49 | struct Hash *a; /* LUA_TTABLE */ |
| 67 | struct CallInfo *i; /* TAG_LMARK */ | 50 | struct CallInfo *i; /* LUA_TLMARK */ |
| 68 | Number n; /* TAG_NUMBER */ | 51 | Number n; /* LUA_TNUMBER */ |
| 69 | } Value; | 52 | } Value; |
| 70 | 53 | ||
| 71 | 54 | ||
| @@ -80,7 +63,7 @@ typedef union { | |||
| 80 | 63 | ||
| 81 | 64 | ||
| 82 | typedef struct lua_TObject { | 65 | typedef struct lua_TObject { |
| 83 | lua_Tag ttype; | 66 | int ttype; |
| 84 | Value value; | 67 | Value value; |
| 85 | } TObject; | 68 | } TObject; |
| 86 | 69 | ||
| @@ -150,11 +133,15 @@ typedef struct Closure { | |||
| 150 | } f; | 133 | } f; |
| 151 | struct Closure *next; | 134 | struct Closure *next; |
| 152 | struct Closure *mark; /* marked closures (point to itself when not marked) */ | 135 | struct Closure *mark; /* marked closures (point to itself when not marked) */ |
| 153 | int nupvalues; | 136 | short isC; /* 0 for Lua functions, 1 for C functions */ |
| 137 | short nupvalues; | ||
| 154 | TObject upvalue[1]; | 138 | TObject upvalue[1]; |
| 155 | } Closure; | 139 | } Closure; |
| 156 | 140 | ||
| 157 | 141 | ||
| 142 | #define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->isC) | ||
| 143 | |||
| 144 | |||
| 158 | typedef struct Node { | 145 | typedef struct Node { |
| 159 | TObject key; | 146 | TObject key; |
| 160 | TObject val; | 147 | TObject val; |
| @@ -189,12 +176,12 @@ typedef struct CallInfo { | |||
| 189 | } CallInfo; | 176 | } CallInfo; |
| 190 | 177 | ||
| 191 | 178 | ||
| 192 | extern const lua_Type luaO_typearr[]; | ||
| 193 | extern const TObject luaO_nilobject; | 179 | extern const TObject luaO_nilobject; |
| 180 | extern const char *const luaO_typenames[]; | ||
| 181 | |||
| 182 | |||
| 183 | #define luaO_typename(o) (luaO_typenames[ttype(o)]) | ||
| 194 | 184 | ||
| 195 | #define luaO_tag2type(t) (luaO_typearr[(int)(t)]) | ||
| 196 | #define luaO_type(o) (luaO_tag2type(ttype(o))) | ||
| 197 | #define luaO_typename(L, o) (lua_typename(L, luaO_type(o))) | ||
| 198 | 185 | ||
| 199 | lint32 luaO_power2 (lint32 n); | 186 | lint32 luaO_power2 (lint32 n); |
| 200 | char *luaO_openspace (lua_State *L, size_t n); | 187 | char *luaO_openspace (lua_State *L, size_t n); |
