aboutsummaryrefslogtreecommitdiff
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-ca6fe7449a74efde6f959605dbe77acf3e64ca0b.tar.gz
lua-ca6fe7449a74efde6f959605dbe77acf3e64ca0b.tar.bz2
lua-ca6fe7449a74efde6f959605dbe77acf3e64ca0b.zip
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 @@
1/* 1/*
2** $Id: lobject.h,v 2.132 2018/01/28 12:07:53 roberto Exp roberto $ 2** $Id: lobject.h,v 2.133 2018/01/28 15:13:26 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*/
@@ -365,47 +365,53 @@ typedef union UTString {
365 365
366 366
367/* 367/*
368** Header for userdata; memory area follows the end of this structure 368** {==================================================================
369** (aligned according to 'UUdata'; see next). 369** Userdata
370** ===================================================================
371*/
372
373/* Ensures that addresses after this type are always fully aligned. */
374typedef union UValue {
375 TValue uv;
376 LUAI_MAXALIGN; /* ensures maximum alignment for udata bytes */
377} UValue;
378
379
380/*
381** Header for userdata; memory area follows the end of this structure.
370*/ 382*/
371typedef struct Udata { 383typedef struct Udata {
372 CommonHeader; 384 CommonHeader;
373 lu_byte ttuv_; /* user value's tag */ 385 unsigned short nuvalue; /* number of user values */
374 struct Table *metatable;
375 size_t len; /* number of bytes */ 386 size_t len; /* number of bytes */
376 union Value user_; /* user value */ 387 struct Table *metatable;
388 GCObject *gclist;
389 UValue uv[1]; /* user values */
377} Udata; 390} Udata;
378 391
379 392
380/* 393/* computes the offset of the memory area of a userdata */
381** Ensures that address after this type is always fully aligned. 394#define udatamemoffset(nuv) (sizeof(Udata) + (sizeof(UValue) * ((nuv) - 1)))
382*/
383typedef union UUdata {
384 LUAI_MAXALIGN; /* ensures maximum alignment for 'local' udata */
385 Udata uv;
386} UUdata;
387
388 395
389/* 396/*
390** Get the address of memory block inside 'Udata'. 397** Get the address of the memory block inside 'Udata'.
391** (Access to 'ttuv_' ensures that value is really a 'Udata'.)
392*/ 398*/
393#define getudatamem(u) \ 399#define getudatamem(u) (cast_charp(u) + udatamemoffset((u)->nuvalue))
394 check_exp(sizeof((u)->ttuv_), (cast_charp(u) + sizeof(UUdata)))
395 400
396#define setuservalue(L,u,o) \ 401/* computes the size of a userdata */
397 { const TValue *io=(o); Udata *iu = (u); \ 402#define sizeudata(nuv,nb) (udatamemoffset(nuv) + (nb))
398 iu->user_ = io->value_; iu->ttuv_ = rttype(io); \
399 checkliveness(L,io); }
400 403
404/* }================================================================== */
401 405
402#define getuservalue(L,u,o) \
403 { TValue *io=(o); const Udata *iu = (u); \
404 io->value_ = iu->user_; settt_(io, iu->ttuv_); \
405 checkliveness(L,io); }
406 406
407 407
408/* 408/*
409** {==================================================================
410** Prototypes
411** ===================================================================
412*/
413
414/*
409** Description of an upvalue for function prototypes 415** Description of an upvalue for function prototypes
410*/ 416*/
411typedef struct Upvaldesc { 417typedef struct Upvaldesc {
@@ -471,6 +477,8 @@ typedef struct Proto {
471 GCObject *gclist; 477 GCObject *gclist;
472} Proto; 478} Proto;
473 479
480/* }================================================================== */
481
474 482
475 483
476/* 484/*