summaryrefslogtreecommitdiff
path: root/lobject.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-20 13:52:50 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-20 13:52:50 -0300
commitca6fe7449a74efde6f959605dbe77acf3e64ca0b (patch)
treea6190e813ff712f7db750d4ecd3afd3ac9c0dbab /lobject.h
parent1afd5a152dc8b3a304236dc4e07bca38ea5eb53a (diff)
downloadlua-github-ca6fe7449a74efde6f959605dbe77acf3e64ca0b.tar.gz
userdata can have multiple user values
Diffstat (limited to 'lobject.h')
-rw-r--r--lobject.h60
1 files changed, 34 insertions, 26 deletions
diff --git a/lobject.h b/lobject.h
index 01bd39fa..03396f11 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.h,v 2.132 2018/01/28 12:07:53 roberto Exp roberto $
+** $Id: lobject.h,v 2.133 2018/01/28 15:13:26 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@@ -365,47 +365,53 @@ typedef union UTString {
/*
-** Header for userdata; memory area follows the end of this structure
-** (aligned according to 'UUdata'; see next).
+** {==================================================================
+** Userdata
+** ===================================================================
+*/
+
+/* Ensures that addresses after this type are always fully aligned. */
+typedef union UValue {
+ TValue uv;
+ LUAI_MAXALIGN; /* ensures maximum alignment for udata bytes */
+} UValue;
+
+
+/*
+** Header for userdata; memory area follows the end of this structure.
*/
typedef struct Udata {
CommonHeader;
- lu_byte ttuv_; /* user value's tag */
- struct Table *metatable;
+ unsigned short nuvalue; /* number of user values */
size_t len; /* number of bytes */
- union Value user_; /* user value */
+ struct Table *metatable;
+ GCObject *gclist;
+ UValue uv[1]; /* user values */
} Udata;
-/*
-** Ensures that address after this type is always fully aligned.
-*/
-typedef union UUdata {
- LUAI_MAXALIGN; /* ensures maximum alignment for 'local' udata */
- Udata uv;
-} UUdata;
-
+/* computes the offset of the memory area of a userdata */
+#define udatamemoffset(nuv) (sizeof(Udata) + (sizeof(UValue) * ((nuv) - 1)))
/*
-** Get the address of memory block inside 'Udata'.
-** (Access to 'ttuv_' ensures that value is really a 'Udata'.)
+** Get the address of the memory block inside 'Udata'.
*/
-#define getudatamem(u) \
- check_exp(sizeof((u)->ttuv_), (cast_charp(u) + sizeof(UUdata)))
+#define getudatamem(u) (cast_charp(u) + udatamemoffset((u)->nuvalue))
-#define setuservalue(L,u,o) \
- { const TValue *io=(o); Udata *iu = (u); \
- iu->user_ = io->value_; iu->ttuv_ = rttype(io); \
- checkliveness(L,io); }
+/* computes the size of a userdata */
+#define sizeudata(nuv,nb) (udatamemoffset(nuv) + (nb))
+/* }================================================================== */
-#define getuservalue(L,u,o) \
- { TValue *io=(o); const Udata *iu = (u); \
- io->value_ = iu->user_; settt_(io, iu->ttuv_); \
- checkliveness(L,io); }
/*
+** {==================================================================
+** Prototypes
+** ===================================================================
+*/
+
+/*
** Description of an upvalue for function prototypes
*/
typedef struct Upvaldesc {
@@ -471,6 +477,8 @@ typedef struct Proto {
GCObject *gclist;
} Proto;
+/* }================================================================== */
+
/*