diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-06-06 15:00:19 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-06-06 15:00:19 -0300 |
| commit | d5b83ead90fba27faa344c72406d85987d2460a4 (patch) | |
| tree | 96d73c1b872b6b01a28c0586b871d37185034ba9 /lobject.h | |
| parent | da673d31aaa05e8dff60c0b601b9f15c4f9182a8 (diff) | |
| download | lua-d5b83ead90fba27faa344c72406d85987d2460a4.tar.gz lua-d5b83ead90fba27faa344c72406d85987d2460a4.tar.bz2 lua-d5b83ead90fba27faa344c72406d85987d2460a4.zip | |
new implementation for userdatas, without `keys'
Diffstat (limited to 'lobject.h')
| -rw-r--r-- | lobject.h | 34 |
1 files changed, 19 insertions, 15 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 1.102 2001/04/11 14:42:41 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.103 2001/06/05 18:17:01 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 | */ |
| @@ -29,6 +29,7 @@ | |||
| 29 | 29 | ||
| 30 | typedef union { | 30 | typedef union { |
| 31 | struct TString *ts; | 31 | struct TString *ts; |
| 32 | struct Udata *u; | ||
| 32 | struct Closure *cl; | 33 | struct Closure *cl; |
| 33 | struct Hash *h; | 34 | struct Hash *h; |
| 34 | lua_Number n; /* LUA_TNUMBER */ | 35 | lua_Number n; /* LUA_TNUMBER */ |
| @@ -45,6 +46,7 @@ typedef struct lua_TObject { | |||
| 45 | #define ttype(o) ((o)->tt) | 46 | #define ttype(o) ((o)->tt) |
| 46 | #define nvalue(o) ((o)->value.n) | 47 | #define nvalue(o) ((o)->value.n) |
| 47 | #define tsvalue(o) ((o)->value.ts) | 48 | #define tsvalue(o) ((o)->value.ts) |
| 49 | #define uvalue(o) ((o)->value.u) | ||
| 48 | #define clvalue(o) ((o)->value.cl) | 50 | #define clvalue(o) ((o)->value.cl) |
| 49 | #define hvalue(o) ((o)->value.h) | 51 | #define hvalue(o) ((o)->value.h) |
| 50 | 52 | ||
| @@ -57,7 +59,7 @@ typedef struct lua_TObject { | |||
| 57 | { TObject *_o=(obj); _o->tt=LUA_TSTRING; _o->value.ts=(x); } | 59 | { TObject *_o=(obj); _o->tt=LUA_TSTRING; _o->value.ts=(x); } |
| 58 | 60 | ||
| 59 | #define setuvalue(obj,x) \ | 61 | #define setuvalue(obj,x) \ |
| 60 | { TObject *_o=(obj); _o->tt=LUA_TUSERDATA; _o->value.ts=(x); } | 62 | { TObject *_o=(obj); _o->tt=LUA_TUSERDATA; _o->value.u=(x); } |
| 61 | 63 | ||
| 62 | #define setclvalue(obj,x) \ | 64 | #define setclvalue(obj,x) \ |
| 63 | { TObject *_o=(obj); _o->tt=LUA_TFUNCTION; _o->value.cl=(x); } | 65 | { TObject *_o=(obj); _o->tt=LUA_TFUNCTION; _o->value.cl=(x); } |
| @@ -78,38 +80,40 @@ typedef TObject *StkId; /* index to stack elements */ | |||
| 78 | /* | 80 | /* |
| 79 | ** String headers for string table | 81 | ** String headers for string table |
| 80 | */ | 82 | */ |
| 81 | |||
| 82 | typedef struct TString { | 83 | typedef struct TString { |
| 83 | union { | 84 | lu_hash hash; |
| 84 | struct { /* for strings */ | 85 | int constindex; /* hint to reuse constants */ |
| 85 | lu_hash hash; | ||
| 86 | int constindex; /* hint to reuse constants */ | ||
| 87 | } s; | ||
| 88 | struct { /* for userdata */ | ||
| 89 | int tag; | ||
| 90 | void *value; | ||
| 91 | } d; | ||
| 92 | } u; | ||
| 93 | size_t len; | 86 | size_t len; |
| 94 | int marked; | 87 | int marked; |
| 95 | struct TString *nexthash; /* chain for hash table */ | 88 | struct TString *nexthash; /* chain for hash table */ |
| 96 | } TString; | 89 | } TString; |
| 97 | 90 | ||
| 98 | 91 | ||
| 92 | |||
| 99 | /* | 93 | /* |
| 100 | ** type equivalent to TString, but with maximum alignment requirements | 94 | ** type equivalent to TString, but with maximum alignment requirements |
| 101 | */ | 95 | */ |
| 102 | union L_UTString { | 96 | union L_UTString { |
| 103 | TString ts; | 97 | TString ts; |
| 104 | union L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | 98 | union L_Umaxalign dummy; /* ensures maximum alignment for strings */ |
| 105 | }; | 99 | }; |
| 106 | 100 | ||
| 107 | 101 | ||
| 108 | |||
| 109 | #define getstr(ts) ((l_char *)((union L_UTString *)(ts) + 1)) | 102 | #define getstr(ts) ((l_char *)((union L_UTString *)(ts) + 1)) |
| 110 | #define svalue(o) getstr(tsvalue(o)) | 103 | #define svalue(o) getstr(tsvalue(o)) |
| 111 | 104 | ||
| 112 | 105 | ||
| 106 | |||
| 107 | typedef struct Udata { | ||
| 108 | int tag; | ||
| 109 | void *value; | ||
| 110 | size_t len; | ||
| 111 | int marked; | ||
| 112 | struct Udata *next; /* chain for list of all udata */ | ||
| 113 | } Udata; | ||
| 114 | |||
| 115 | |||
| 116 | |||
| 113 | /* | 117 | /* |
| 114 | ** Function Prototypes | 118 | ** Function Prototypes |
| 115 | */ | 119 | */ |
