Clearer distinction between types and tags

LUA_T* represents only types; tags (types + Variants) are represented
by LUA_V* constants.
This commit is contained in:
Roberto Ierusalimschy 2020-01-31 11:09:53 -03:00
parent 69c7139ff8
commit 46c3587a6f
22 changed files with 231 additions and 213 deletions

22
lapi.c
View File

@ -262,7 +262,7 @@ LUA_API int lua_type (lua_State *L, int idx) {
LUA_API const char *lua_typename (lua_State *L, int t) {
UNUSED(L);
api_check(L, LUA_TNONE <= t && t < LUA_NUMTAGS, "invalid tag");
api_check(L, LUA_TNONE <= t && t < LUA_NUMTYPES, "invalid type");
return ttypename(t);
}
@ -397,10 +397,10 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) {
const TValue *o = index2value(L, idx);
switch (ttypetag(o)) {
case LUA_TSHRSTR: return tsvalue(o)->shrlen;
case LUA_TLNGSTR: return tsvalue(o)->u.lnglen;
case LUA_TUSERDATA: return uvalue(o)->len;
case LUA_TTABLE: return luaH_getn(hvalue(o));
case LUA_VSHRSTR: return tsvalue(o)->shrlen;
case LUA_VLNGSTR: return tsvalue(o)->u.lnglen;
case LUA_VUSERDATA: return uvalue(o)->len;
case LUA_VTABLE: return luaH_getn(hvalue(o));
default: return 0;
}
}
@ -446,8 +446,8 @@ LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
LUA_API const void *lua_topointer (lua_State *L, int idx) {
const TValue *o = index2value(L, idx);
switch (ttypetag(o)) {
case LUA_TLCF: return cast_voidp(cast_sizet(fvalue(o)));
case LUA_TUSERDATA: case LUA_TLIGHTUSERDATA:
case LUA_VLCF: return cast_voidp(cast_sizet(fvalue(o)));
case LUA_VUSERDATA: case LUA_VLIGHTUSERDATA:
return touserdata(o);
default: {
if (iscollectable(o))
@ -1312,7 +1312,7 @@ LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) {
static const char *aux_upvalue (TValue *fi, int n, TValue **val,
GCObject **owner) {
switch (ttypetag(fi)) {
case LUA_TCCL: { /* C closure */
case LUA_VCCL: { /* C closure */
CClosure *f = clCvalue(fi);
if (!(cast_uint(n) - 1u < cast_uint(f->nupvalues)))
return NULL; /* 'n' not in [1, f->nupvalues] */
@ -1320,7 +1320,7 @@ static const char *aux_upvalue (TValue *fi, int n, TValue **val,
if (owner) *owner = obj2gco(f);
return "";
}
case LUA_TLCL: { /* Lua closure */
case LUA_VLCL: { /* Lua closure */
LClosure *f = clLvalue(fi);
TString *name;
Proto *p = f->p;
@ -1383,10 +1383,10 @@ static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) {
LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) {
TValue *fi = index2value(L, fidx);
switch (ttypetag(fi)) {
case LUA_TLCL: { /* lua closure */
case LUA_VLCL: { /* lua closure */
return *getupvalref(L, fidx, n, NULL);
}
case LUA_TCCL: { /* C closure */
case LUA_VCCL: { /* C closure */
CClosure *f = clCvalue(fi);
api_check(L, 1 <= n && n <= f->nupvalues, "invalid upvalue index");
return &f->upvalue[n - 1];

12
lcode.c
View File

@ -678,22 +678,22 @@ static void luaK_float (FuncState *fs, int reg, lua_Number f) {
*/
static void const2exp (TValue *v, expdesc *e) {
switch (ttypetag(v)) {
case LUA_TNUMINT:
case LUA_VNUMINT:
e->k = VKINT; e->u.ival = ivalue(v);
break;
case LUA_TNUMFLT:
case LUA_VNUMFLT:
e->k = VKFLT; e->u.nval = fltvalue(v);
break;
case LUA_TFALSE:
case LUA_VFALSE:
e->k = VFALSE;
break;
case LUA_TTRUE:
case LUA_VTRUE:
e->k = VTRUE;
break;
case LUA_TNIL:
case LUA_VNIL:
e->k = VNIL;
break;
case LUA_TSHRSTR: case LUA_TLNGSTR:
case LUA_VSHRSTR: case LUA_VLNGSTR:
e->k = VKSTR; e->u.strval = tsvalue(v);
break;
default: lua_assert(0);

View File

@ -31,7 +31,7 @@
#define noLuaClosure(f) ((f) == NULL || (f)->c.tt == LUA_TCCL)
#define noLuaClosure(f) ((f) == NULL || (f)->c.tt == LUA_VCCL)
/* Active Lua function (given call info) */

6
ldo.c
View File

@ -459,10 +459,10 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
lua_CFunction f;
retry:
switch (ttypetag(s2v(func))) {
case LUA_TCCL: /* C closure */
case LUA_VCCL: /* C closure */
f = clCvalue(s2v(func))->f;
goto Cfunc;
case LUA_TLCF: /* light C function */
case LUA_VLCF: /* light C function */
f = fvalue(s2v(func));
Cfunc: {
int n; /* number of returns */
@ -485,7 +485,7 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
luaD_poscall(L, ci, n);
break;
}
case LUA_TLCL: { /* Lua function */
case LUA_VLCL: { /* Lua function */
CallInfo *ci;
Proto *p = clLvalue(s2v(func))->p;
int narg = cast_int(L->top - func) - 1; /* number of real arguments */

18
ldump.c
View File

@ -111,21 +111,21 @@ static void DumpConstants (const Proto *f, DumpState *D) {
DumpInt(n, D);
for (i = 0; i < n; i++) {
const TValue *o = &f->k[i];
DumpByte(ttypetag(o), D);
switch (ttypetag(o)) {
case LUA_TNIL: case LUA_TFALSE: case LUA_TTRUE:
break;
case LUA_TNUMFLT:
int tt = ttypetag(o);
DumpByte(tt, D);
switch (tt) {
case LUA_VNUMFLT:
DumpNumber(fltvalue(o), D);
break;
case LUA_TNUMINT:
case LUA_VNUMINT:
DumpInteger(ivalue(o), D);
break;
case LUA_TSHRSTR:
case LUA_TLNGSTR:
case LUA_VSHRSTR:
case LUA_VLNGSTR:
DumpString(tsvalue(o), D);
break;
default: lua_assert(0);
default:
lua_assert(tt == LUA_VNIL || tt == LUA_VFALSE || tt == LUA_VTRUE);
}
}
}

10
lfunc.c
View File

@ -25,7 +25,7 @@
CClosure *luaF_newCclosure (lua_State *L, int nupvals) {
GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(nupvals));
GCObject *o = luaC_newobj(L, LUA_VCCL, sizeCclosure(nupvals));
CClosure *c = gco2ccl(o);
c->nupvalues = cast_byte(nupvals);
return c;
@ -33,7 +33,7 @@ CClosure *luaF_newCclosure (lua_State *L, int nupvals) {
LClosure *luaF_newLclosure (lua_State *L, int nupvals) {
GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(nupvals));
GCObject *o = luaC_newobj(L, LUA_VLCL, sizeLclosure(nupvals));
LClosure *c = gco2lcl(o);
c->p = NULL;
c->nupvalues = cast_byte(nupvals);
@ -48,7 +48,7 @@ LClosure *luaF_newLclosure (lua_State *L, int nupvals) {
void luaF_initupvals (lua_State *L, LClosure *cl) {
int i;
for (i = 0; i < cl->nupvalues; i++) {
GCObject *o = luaC_newobj(L, LUA_TUPVAL, sizeof(UpVal));
GCObject *o = luaC_newobj(L, LUA_VUPVAL, sizeof(UpVal));
UpVal *uv = gco2upv(o);
uv->v = &uv->u.value; /* make it closed */
setnilvalue(uv->v);
@ -63,7 +63,7 @@ void luaF_initupvals (lua_State *L, LClosure *cl) {
** open upvalues of 'L' after entry 'prev'.
**/
static UpVal *newupval (lua_State *L, int tbc, StkId level, UpVal **prev) {
GCObject *o = luaC_newobj(L, LUA_TUPVAL, sizeof(UpVal));
GCObject *o = luaC_newobj(L, LUA_VUPVAL, sizeof(UpVal));
UpVal *uv = gco2upv(o);
UpVal *next = *prev;
uv->v = s2v(level); /* current value lives in the stack */
@ -243,7 +243,7 @@ int luaF_close (lua_State *L, StkId level, int status) {
Proto *luaF_newproto (lua_State *L) {
GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto));
GCObject *o = luaC_newobj(L, LUA_VPROTO, sizeof(Proto));
Proto *f = gco2p(o);
f->k = NULL;
f->sizek = 0;

58
lgc.c
View File

@ -119,12 +119,12 @@ static void entersweep (lua_State *L);
static GCObject **getgclist (GCObject *o) {
switch (o->tt) {
case LUA_TTABLE: return &gco2t(o)->gclist;
case LUA_TLCL: return &gco2lcl(o)->gclist;
case LUA_TCCL: return &gco2ccl(o)->gclist;
case LUA_TTHREAD: return &gco2th(o)->gclist;
case LUA_TPROTO: return &gco2p(o)->gclist;
case LUA_TUSERDATA: {
case LUA_VTABLE: return &gco2t(o)->gclist;
case LUA_VLCL: return &gco2lcl(o)->gclist;
case LUA_VCCL: return &gco2ccl(o)->gclist;
case LUA_VTHREAD: return &gco2th(o)->gclist;
case LUA_VPROTO: return &gco2p(o)->gclist;
case LUA_VUSERDATA: {
Udata *u = gco2u(o);
lua_assert(u->nuvalue > 0);
return &u->gclist;
@ -268,19 +268,19 @@ GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) {
static void reallymarkobject (global_State *g, GCObject *o) {
white2gray(o);
switch (o->tt) {
case LUA_TSHRSTR:
case LUA_TLNGSTR: {
case LUA_VSHRSTR:
case LUA_VLNGSTR: {
gray2black(o);
break;
}
case LUA_TUPVAL: {
case LUA_VUPVAL: {
UpVal *uv = gco2upv(o);
if (!upisopen(uv)) /* open upvalues are kept gray */
gray2black(o);
markvalue(g, uv->v); /* mark its content */
break;
}
case LUA_TUSERDATA: {
case LUA_VUSERDATA: {
Udata *u = gco2u(o);
if (u->nuvalue == 0) { /* no user values? */
markobjectN(g, u->metatable); /* mark its metatable */
@ -289,8 +289,8 @@ static void reallymarkobject (global_State *g, GCObject *o) {
}
/* else... */
} /* FALLTHROUGH */
case LUA_TLCL: case LUA_TCCL: case LUA_TTABLE:
case LUA_TTHREAD: case LUA_TPROTO: {
case LUA_VLCL: case LUA_VCCL: case LUA_VTABLE:
case LUA_VTHREAD: case LUA_VPROTO: {
linkobjgclist(o, g->gray);
break;
}
@ -598,12 +598,12 @@ static lu_mem propagatemark (global_State *g) {
gray2black(o);
g->gray = *getgclist(o); /* remove from 'gray' list */
switch (o->tt) {
case LUA_TTABLE: return traversetable(g, gco2t(o));
case LUA_TUSERDATA: return traverseudata(g, gco2u(o));
case LUA_TLCL: return traverseLclosure(g, gco2lcl(o));
case LUA_TCCL: return traverseCclosure(g, gco2ccl(o));
case LUA_TPROTO: return traverseproto(g, gco2p(o));
case LUA_TTHREAD: {
case LUA_VTABLE: return traversetable(g, gco2t(o));
case LUA_VUSERDATA: return traverseudata(g, gco2u(o));
case LUA_VLCL: return traverseLclosure(g, gco2lcl(o));
case LUA_VCCL: return traverseCclosure(g, gco2ccl(o));
case LUA_VPROTO: return traverseproto(g, gco2p(o));
case LUA_VTHREAD: {
lua_State *th = gco2th(o);
linkgclist(th, g->grayagain); /* insert into 'grayagain' list */
black2gray(o);
@ -710,34 +710,34 @@ static void freeupval (lua_State *L, UpVal *uv) {
static void freeobj (lua_State *L, GCObject *o) {
switch (o->tt) {
case LUA_TPROTO:
case LUA_VPROTO:
luaF_freeproto(L, gco2p(o));
break;
case LUA_TUPVAL:
case LUA_VUPVAL:
freeupval(L, gco2upv(o));
break;
case LUA_TLCL:
case LUA_VLCL:
luaM_freemem(L, o, sizeLclosure(gco2lcl(o)->nupvalues));
break;
case LUA_TCCL:
case LUA_VCCL:
luaM_freemem(L, o, sizeCclosure(gco2ccl(o)->nupvalues));
break;
case LUA_TTABLE:
case LUA_VTABLE:
luaH_free(L, gco2t(o));
break;
case LUA_TTHREAD:
case LUA_VTHREAD:
luaE_freethread(L, gco2th(o));
break;
case LUA_TUSERDATA: {
case LUA_VUSERDATA: {
Udata *u = gco2u(o);
luaM_freemem(L, o, sizeudata(u->nuvalue, u->len));
break;
}
case LUA_TSHRSTR:
case LUA_VSHRSTR:
luaS_remove(L, gco2ts(o)); /* remove it from hash table */
luaM_freemem(L, o, sizelstring(gco2ts(o)->shrlen));
break;
case LUA_TLNGSTR:
case LUA_VLNGSTR:
luaM_freemem(L, o, sizelstring(gco2ts(o)->u.lnglen));
break;
default: lua_assert(0);
@ -1049,7 +1049,7 @@ static GCObject **correctgraylist (GCObject **p) {
GCObject *curr;
while ((curr = *p) != NULL) {
switch (curr->tt) {
case LUA_TTABLE: case LUA_TUSERDATA: {
case LUA_VTABLE: case LUA_VUSERDATA: {
GCObject **next = getgclist(curr);
if (getage(curr) == G_TOUCHED1) { /* touched in this cycle? */
lua_assert(isgray(curr));
@ -1069,7 +1069,7 @@ static GCObject **correctgraylist (GCObject **p) {
}
break;
}
case LUA_TTHREAD: {
case LUA_VTHREAD: {
lua_State *th = gco2th(curr);
lua_assert(!isblack(th));
if (iswhite(th)) /* new object? */

View File

@ -215,7 +215,7 @@ static int f_close (lua_State *L) {
static int io_close (lua_State *L) {
if (lua_isnone(L, 1)) /* no argument? */
lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */
lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use default output */
return f_close(L);
}
@ -296,7 +296,7 @@ static FILE *getiofile (lua_State *L, const char *findex) {
lua_getfield(L, LUA_REGISTRYINDEX, findex);
p = (LStream *)lua_touserdata(L, -1);
if (isclosed(p))
luaL_error(L, "standard %s file is closed", findex + IOPREF_LEN);
luaL_error(L, "default %s file is closed", findex + IOPREF_LEN);
return p->f;
}

138
lobject.h
View File

@ -17,16 +17,16 @@
/*
** Extra tags for collectable non-values
** Extra types for collectable non-values
*/
#define LUA_TUPVAL LUA_NUMTAGS /* upvalues */
#define LUA_TPROTO (LUA_NUMTAGS+1) /* function prototypes */
#define LUA_TUPVAL LUA_NUMTYPES /* upvalues */
#define LUA_TPROTO (LUA_NUMTYPES+1) /* function prototypes */
/*
** number of all possible tags (including LUA_TNONE)
** number of all possible types (including LUA_TNONE)
*/
#define LUA_TOTALTAGS (LUA_TPROTO + 2)
#define LUA_TOTALTYPES (LUA_TPROTO + 2)
/*
@ -154,30 +154,28 @@ typedef StackValue *StkId;
** ===================================================================
*/
/* Standard nil */
#define LUA_VNIL makevariant(LUA_TNIL, 1)
/* Empty slot (which might be different from a slot containing nil) */
#define LUA_VEMPTY makevariant(LUA_TNIL, 2)
/* Value returned for a key not found in a table (absent key) */
#define LUA_VABSTKEY makevariant(LUA_TNIL, 3)
/* macro to test for (any kind of) nil */
#define ttisnil(v) checktype((v), LUA_TNIL)
/* macro to test for a "pure" nil */
#define ttisstrictnil(o) checktag((o), LUA_TNIL)
/* macro to test for a standard nil */
#define ttisstrictnil(o) checktag((o), LUA_VNIL)
#define setnilvalue(obj) settt_(obj, LUA_TNIL)
#define setnilvalue(obj) settt_(obj, LUA_VNIL)
/*
** Variant tag, used only in tables to signal an empty slot
** (which might be different from a slot containing nil)
*/
#define LUA_TEMPTY makevariant(LUA_TNIL, 1)
/*
** Variant used only in the value returned for a key not found in a
** table (absent key).
*/
#define LUA_TABSTKEY makevariant(LUA_TNIL, 2)
#define isabstkey(v) checktag((v), LUA_TABSTKEY)
#define isabstkey(v) checktag((v), LUA_VABSTKEY)
/*
@ -195,11 +193,11 @@ typedef StackValue *StkId;
/* macro defining a value corresponding to an absent key */
#define ABSTKEYCONSTANT {NULL}, LUA_TABSTKEY
#define ABSTKEYCONSTANT {NULL}, LUA_VABSTKEY
/* mark an entry as empty */
#define setempty(v) settt_(v, LUA_TEMPTY)
#define setempty(v) settt_(v, LUA_VEMPTY)
@ -213,19 +211,19 @@ typedef StackValue *StkId;
*/
#define LUA_TFALSE makevariant(LUA_TBOOLEAN, 1)
#define LUA_TTRUE makevariant(LUA_TBOOLEAN, 2)
#define LUA_VFALSE makevariant(LUA_TBOOLEAN, 1)
#define LUA_VTRUE makevariant(LUA_TBOOLEAN, 2)
#define ttisboolean(o) checktype((o), LUA_TBOOLEAN)
#define ttisfalse(o) checktag((o), LUA_TFALSE)
#define ttistrue(o) checktag((o), LUA_TTRUE)
#define ttisfalse(o) checktag((o), LUA_VFALSE)
#define ttistrue(o) checktag((o), LUA_VTRUE)
#define l_isfalse(o) (ttisfalse(o) || ttisnil(o))
#define setbfvalue(obj) settt_(obj, LUA_TFALSE)
#define setbtvalue(obj) settt_(obj, LUA_TTRUE)
#define setbfvalue(obj) settt_(obj, LUA_VFALSE)
#define setbtvalue(obj) settt_(obj, LUA_VTRUE)
/* }================================================================== */
@ -236,13 +234,15 @@ typedef StackValue *StkId;
** ===================================================================
*/
#define ttisthread(o) checktag((o), ctb(LUA_TTHREAD))
#define LUA_VTHREAD makevariant(LUA_TTHREAD, 1)
#define ttisthread(o) checktag((o), ctb(LUA_VTHREAD))
#define thvalue(o) check_exp(ttisthread(o), gco2th(val_(o).gc))
#define setthvalue(L,obj,x) \
{ TValue *io = (obj); lua_State *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTHREAD)); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VTHREAD)); \
checkliveness(L,io); }
#define setthvalue2s(L,o,t) setthvalue(L,s2v(o),t)
@ -295,12 +295,12 @@ typedef struct GCObject {
*/
/* Variant tags for numbers */
#define LUA_TNUMINT makevariant(LUA_TNUMBER, 1) /* integer numbers */
#define LUA_TNUMFLT makevariant(LUA_TNUMBER, 2) /* float numbers */
#define LUA_VNUMINT makevariant(LUA_TNUMBER, 1) /* integer numbers */
#define LUA_VNUMFLT makevariant(LUA_TNUMBER, 2) /* float numbers */
#define ttisnumber(o) checktype((o), LUA_TNUMBER)
#define ttisfloat(o) checktag((o), LUA_TNUMFLT)
#define ttisinteger(o) checktag((o), LUA_TNUMINT)
#define ttisfloat(o) checktag((o), LUA_VNUMFLT)
#define ttisinteger(o) checktag((o), LUA_VNUMINT)
#define nvalue(o) check_exp(ttisnumber(o), \
(ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o)))
@ -311,13 +311,13 @@ typedef struct GCObject {
#define ivalueraw(v) ((v).i)
#define setfltvalue(obj,x) \
{ TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); }
{ TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_VNUMFLT); }
#define chgfltvalue(obj,x) \
{ TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); }
#define setivalue(obj,x) \
{ TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_TNUMINT); }
{ TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_VNUMINT); }
#define chgivalue(obj,x) \
{ TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); }
@ -332,12 +332,12 @@ typedef struct GCObject {
*/
/* Variant tags for strings */
#define LUA_TSHRSTR makevariant(LUA_TSTRING, 1) /* short strings */
#define LUA_TLNGSTR makevariant(LUA_TSTRING, 2) /* long strings */
#define LUA_VSHRSTR makevariant(LUA_TSTRING, 1) /* short strings */
#define LUA_VLNGSTR makevariant(LUA_TSTRING, 2) /* long strings */
#define ttisstring(o) checktype((o), LUA_TSTRING)
#define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR))
#define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR))
#define ttisshrstring(o) checktag((o), ctb(LUA_VSHRSTR))
#define ttislngstring(o) checktag((o), ctb(LUA_VLNGSTR))
#define tsvalueraw(v) (gco2ts((v).gc))
@ -384,7 +384,7 @@ typedef struct TString {
#define svalue(o) getstr(tsvalue(o))
/* get string length from 'TString *s' */
#define tsslen(s) ((s)->tt == LUA_TSHRSTR ? (s)->shrlen : (s)->u.lnglen)
#define tsslen(s) ((s)->tt == LUA_VSHRSTR ? (s)->shrlen : (s)->u.lnglen)
/* get string length from 'TValue *o' */
#define vslen(o) tsslen(tsvalue(o))
@ -398,8 +398,16 @@ typedef struct TString {
** ===================================================================
*/
#define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA)
#define ttisfulluserdata(o) checktype((o), LUA_TUSERDATA)
/*
** Light userdata should be a variant of userdata, but for compatibility
** reasons they are also different types.
*/
#define LUA_VLIGHTUSERDATA makevariant(LUA_TLIGHTUSERDATA, 1)
#define LUA_VUSERDATA makevariant(LUA_TUSERDATA, 1)
#define ttislightuserdata(o) checktag((o), LUA_VLIGHTUSERDATA)
#define ttisfulluserdata(o) checktag((o), ctb(LUA_VUSERDATA))
#define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p)
#define uvalue(o) check_exp(ttisfulluserdata(o), gco2u(val_(o).gc))
@ -407,11 +415,11 @@ typedef struct TString {
#define pvalueraw(v) ((v).p)
#define setpvalue(obj,x) \
{ TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); }
{ TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_VLIGHTUSERDATA); }
#define setuvalue(L,obj,x) \
{ TValue *io = (obj); Udata *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VUSERDATA)); \
checkliveness(L,io); }
@ -474,6 +482,9 @@ typedef struct Udata0 {
** ===================================================================
*/
#define LUA_VPROTO makevariant(LUA_TPROTO, 1)
/*
** Description of an upvalue for function prototypes
*/
@ -548,16 +559,19 @@ typedef struct Proto {
** ===================================================================
*/
#define LUA_VUPVAL makevariant(LUA_TUPVAL, 1)
/* Variant tags for functions */
#define LUA_TLCL makevariant(LUA_TFUNCTION, 1) /* Lua closure */
#define LUA_TLCF makevariant(LUA_TFUNCTION, 2) /* light C function */
#define LUA_TCCL makevariant(LUA_TFUNCTION, 3) /* C closure */
#define LUA_VLCL makevariant(LUA_TFUNCTION, 1) /* Lua closure */
#define LUA_VLCF makevariant(LUA_TFUNCTION, 2) /* light C function */
#define LUA_VCCL makevariant(LUA_TFUNCTION, 3) /* C closure */
#define ttisfunction(o) checktype(o, LUA_TFUNCTION)
#define ttisclosure(o) ((rawtt(o) & 0x1F) == LUA_TLCL)
#define ttisLclosure(o) checktag((o), ctb(LUA_TLCL))
#define ttislcf(o) checktag((o), LUA_TLCF)
#define ttisCclosure(o) checktag((o), ctb(LUA_TCCL))
#define ttisclosure(o) ((rawtt(o) & 0x1F) == LUA_VLCL)
#define ttisLclosure(o) checktag((o), ctb(LUA_VLCL))
#define ttislcf(o) checktag((o), LUA_VLCF)
#define ttisCclosure(o) checktag((o), ctb(LUA_VCCL))
#define isLfunction(o) ttisLclosure(o)
@ -570,17 +584,17 @@ typedef struct Proto {
#define setclLvalue(L,obj,x) \
{ TValue *io = (obj); LClosure *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TLCL)); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VLCL)); \
checkliveness(L,io); }
#define setclLvalue2s(L,o,cl) setclLvalue(L,s2v(o),cl)
#define setfvalue(obj,x) \
{ TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); }
{ TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_VLCF); }
#define setclCvalue(L,obj,x) \
{ TValue *io = (obj); CClosure *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TCCL)); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VCCL)); \
checkliveness(L,io); }
@ -636,13 +650,15 @@ typedef union Closure {
** ===================================================================
*/
#define ttistable(o) checktag((o), ctb(LUA_TTABLE))
#define LUA_VTABLE makevariant(LUA_TTABLE, 1)
#define ttistable(o) checktag((o), ctb(LUA_VTABLE))
#define hvalue(o) check_exp(ttistable(o), gco2t(val_(o).gc))
#define sethvalue(L,obj,x) \
{ TValue *io = (obj); Table *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTABLE)); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VTABLE)); \
checkliveness(L,io); }
#define sethvalue2s(L,o,h) sethvalue(L,s2v(o),h)
@ -713,9 +729,9 @@ typedef struct Table {
#define keyval(node) ((node)->u.key_val)
#define keyisnil(node) (keytt(node) == LUA_TNIL)
#define keyisinteger(node) (keytt(node) == LUA_TNUMINT)
#define keyisinteger(node) (keytt(node) == LUA_VNUMINT)
#define keyival(node) (keyval(node).i)
#define keyisshrstr(node) (keytt(node) == ctb(LUA_TSHRSTR))
#define keyisshrstr(node) (keytt(node) == ctb(LUA_VSHRSTR))
#define keystrval(node) (gco2ts(keyval(node).gc))
#define setnilkey(node) (keytt(node) = LUA_TNIL)

View File

@ -17,11 +17,11 @@
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
iABC C(8) | B(8) |k| A(8) | Op(7) |
iABx Bx(17) | A(8) | Op(7) |
iAsBx sBx (signed)(17) | A(8) | Op(7) |
iAx Ax(25) | Op(7) |
isJ sJ(25) | Op(7) |
iABC C(8) | B(8) |k| A(8) | Op(7) |
iABx Bx(17) | A(8) | Op(7) |
iAsBx sBx (signed)(17) | A(8) | Op(7) |
iAx Ax(25) | Op(7) |
isJ sJ(25) | Op(7) |
A signed argument is represented in excess K: the represented value is
the written unsigned value minus K, where K is half the maximum for the

View File

@ -318,7 +318,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
/* create new thread */
L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l;
L1->marked = luaC_white(g);
L1->tt = LUA_TTHREAD;
L1->tt = LUA_VTHREAD;
/* link it on list 'allgc' */
L1->next = g->allgc;
g->allgc = obj2gco(L1);
@ -382,7 +382,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
if (l == NULL) return NULL;
L = &l->l.l;
g = &l->g;
L->tt = LUA_TTHREAD;
L->tt = LUA_VTHREAD;
g->currentwhite = bitmask(WHITE0BIT);
L->marked = luaC_white(g);
preinit_thread(L, g);

View File

@ -327,15 +327,15 @@ union GCUnion {
/* macros to convert a GCObject into a specific value */
#define gco2ts(o) \
check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))
#define gco2u(o) check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u))
#define gco2lcl(o) check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l))
#define gco2ccl(o) check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c))
#define gco2u(o) check_exp((o)->tt == LUA_VUSERDATA, &((cast_u(o))->u))
#define gco2lcl(o) check_exp((o)->tt == LUA_VLCL, &((cast_u(o))->cl.l))
#define gco2ccl(o) check_exp((o)->tt == LUA_VCCL, &((cast_u(o))->cl.c))
#define gco2cl(o) \
check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))
#define gco2t(o) check_exp((o)->tt == LUA_TTABLE, &((cast_u(o))->h))
#define gco2p(o) check_exp((o)->tt == LUA_TPROTO, &((cast_u(o))->p))
#define gco2th(o) check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th))
#define gco2upv(o) check_exp((o)->tt == LUA_TUPVAL, &((cast_u(o))->upv))
#define gco2t(o) check_exp((o)->tt == LUA_VTABLE, &((cast_u(o))->h))
#define gco2p(o) check_exp((o)->tt == LUA_VPROTO, &((cast_u(o))->p))
#define gco2th(o) check_exp((o)->tt == LUA_VTHREAD, &((cast_u(o))->th))
#define gco2upv(o) check_exp((o)->tt == LUA_VUPVAL, &((cast_u(o))->upv))
/*

View File

@ -43,7 +43,7 @@
*/
int luaS_eqlngstr (TString *a, TString *b) {
size_t len = a->u.lnglen;
lua_assert(a->tt == LUA_TLNGSTR && b->tt == LUA_TLNGSTR);
lua_assert(a->tt == LUA_VLNGSTR && b->tt == LUA_VLNGSTR);
return (a == b) || /* same instance or... */
((len == b->u.lnglen) && /* equal length and ... */
(memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */
@ -60,7 +60,7 @@ unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {
unsigned int luaS_hashlongstr (TString *ts) {
lua_assert(ts->tt == LUA_TLNGSTR);
lua_assert(ts->tt == LUA_VLNGSTR);
if (ts->extra == 0) { /* no hash? */
ts->hash = luaS_hash(getstr(ts), ts->u.lnglen, ts->hash);
ts->extra = 1; /* now it has its hash */
@ -165,7 +165,7 @@ static TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) {
TString *luaS_createlngstrobj (lua_State *L, size_t l) {
TString *ts = createstrobj(L, l, LUA_TLNGSTR, G(L)->seed);
TString *ts = createstrobj(L, l, LUA_VLNGSTR, G(L)->seed);
ts->u.lnglen = l;
return ts;
}
@ -215,7 +215,7 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) {
growstrtab(L, tb);
list = &tb->hash[lmod(h, tb->size)]; /* rehash with new size */
}
ts = createstrobj(L, l, LUA_TSHRSTR, h);
ts = createstrobj(L, l, LUA_VSHRSTR, h);
memcpy(getstr(ts), str, l * sizeof(char));
ts->shrlen = cast_byte(l);
ts->u.hnext = *list;
@ -271,7 +271,7 @@ Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue) {
GCObject *o;
if (unlikely(s > MAX_SIZE - udatamemoffset(nuvalue)))
luaM_toobig(L);
o = luaC_newobj(L, LUA_TUSERDATA, sizeudata(nuvalue, s));
o = luaC_newobj(L, LUA_VUSERDATA, sizeudata(nuvalue, s));
u = gco2u(o);
u->len = s;
u->nuvalue = nuvalue;

View File

@ -28,13 +28,13 @@
/*
** test whether a string is a reserved word
*/
#define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0)
#define isreserved(s) ((s)->tt == LUA_VSHRSTR && (s)->extra > 0)
/*
** equality for short strings, which are always internalized
*/
#define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b))
#define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b))
LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);

View File

@ -88,8 +88,8 @@
#define dummynode (&dummynode_)
static const Node dummynode_ = {
{{NULL}, LUA_TEMPTY, /* value's value and type */
LUA_TNIL, 0, {NULL}} /* key type, next, and key value */
{{NULL}, LUA_VEMPTY, /* value's value and type */
LUA_VNIL, 0, {NULL}} /* key type, next, and key value */
};
@ -135,21 +135,21 @@ static int l_hashfloat (lua_Number n) {
*/
static Node *mainposition (const Table *t, int ktt, const Value *kvl) {
switch (withvariant(ktt)) {
case LUA_TNUMINT:
case LUA_VNUMINT:
return hashint(t, ivalueraw(*kvl));
case LUA_TNUMFLT:
case LUA_VNUMFLT:
return hashmod(t, l_hashfloat(fltvalueraw(*kvl)));
case LUA_TSHRSTR:
case LUA_VSHRSTR:
return hashstr(t, tsvalueraw(*kvl));
case LUA_TLNGSTR:
case LUA_VLNGSTR:
return hashpow2(t, luaS_hashlongstr(tsvalueraw(*kvl)));
case LUA_TFALSE:
case LUA_VFALSE:
return hashboolean(t, 0);
case LUA_TTRUE:
case LUA_VTRUE:
return hashboolean(t, 1);
case LUA_TLIGHTUSERDATA:
case LUA_VLIGHTUSERDATA:
return hashpointer(t, pvalueraw(*kvl));
case LUA_TLCF:
case LUA_VLCF:
return hashpointer(t, fvalueraw(*kvl));
default:
return hashpointer(t, gcvalueraw(*kvl));
@ -177,17 +177,17 @@ static int equalkey (const TValue *k1, const Node *n2) {
if (rawtt(k1) != keytt(n2)) /* not the same variants? */
return 0; /* cannot be same key */
switch (ttypetag(k1)) {
case LUA_TNIL: case LUA_TFALSE: case LUA_TTRUE:
case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE:
return 1;
case LUA_TNUMINT:
case LUA_VNUMINT:
return (ivalue(k1) == keyival(n2));
case LUA_TNUMFLT:
case LUA_VNUMFLT:
return luai_numeq(fltvalue(k1), fltvalueraw(keyval(n2)));
case LUA_TLIGHTUSERDATA:
case LUA_VLIGHTUSERDATA:
return pvalue(k1) == pvalueraw(keyval(n2));
case LUA_TLCF:
case LUA_VLCF:
return fvalue(k1) == fvalueraw(keyval(n2));
case LUA_TLNGSTR:
case LUA_VLNGSTR:
return luaS_eqlngstr(tsvalue(k1), keystrval(n2));
default:
return gcvalue(k1) == gcvalueraw(keyval(n2));
@ -580,7 +580,7 @@ static void rehash (lua_State *L, Table *t, const TValue *ek) {
Table *luaH_new (lua_State *L) {
GCObject *o = luaC_newobj(L, LUA_TTABLE, sizeof(Table));
GCObject *o = luaC_newobj(L, LUA_VTABLE, sizeof(Table));
Table *t = gco2t(o);
t->metatable = NULL;
t->flags = cast_byte(~0);
@ -710,7 +710,7 @@ const TValue *luaH_getint (Table *t, lua_Integer key) {
*/
const TValue *luaH_getshortstr (Table *t, TString *key) {
Node *n = hashstr(t, key);
lua_assert(key->tt == LUA_TSHRSTR);
lua_assert(key->tt == LUA_VSHRSTR);
for (;;) { /* check whether 'key' is somewhere in the chain */
if (keyisshrstr(n) && eqshrstr(keystrval(n), key))
return gval(n); /* that's it */
@ -725,7 +725,7 @@ const TValue *luaH_getshortstr (Table *t, TString *key) {
const TValue *luaH_getstr (Table *t, TString *key) {
if (key->tt == LUA_TSHRSTR)
if (key->tt == LUA_VSHRSTR)
return luaH_getshortstr(t, key);
else { /* for long strings, use generic case */
TValue ko;
@ -740,10 +740,10 @@ const TValue *luaH_getstr (Table *t, TString *key) {
*/
const TValue *luaH_get (Table *t, const TValue *key) {
switch (ttypetag(key)) {
case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key));
case LUA_TNUMINT: return luaH_getint(t, ivalue(key));
case LUA_TNIL: return &absentkey;
case LUA_TNUMFLT: {
case LUA_VSHRSTR: return luaH_getshortstr(t, tsvalue(key));
case LUA_VNUMINT: return luaH_getint(t, ivalue(key));
case LUA_VNIL: return &absentkey;
case LUA_VNUMFLT: {
lua_Integer k;
if (luaV_flttointeger(fltvalue(key), &k, F2Ieq)) /* integral index? */
return luaH_getint(t, k); /* use specialized version */

View File

@ -303,7 +303,7 @@ static void printobj (global_State *g, GCObject *o) {
ttypename(novariant(o->tt)), (void *)o,
isdead(g,o) ? 'd' : isblack(o) ? 'b' : iswhite(o) ? 'w' : 'g',
"ns01oTt"[getage(o)], o->marked);
if (o->tt == LUA_TSHRSTR || o->tt == LUA_TLNGSTR)
if (o->tt == LUA_VSHRSTR || o->tt == LUA_VLNGSTR)
printf(" '%s'", getstr(gco2ts(o)));
}
@ -435,36 +435,36 @@ static void checkstack (global_State *g, lua_State *L1) {
static void checkrefs (global_State *g, GCObject *o) {
switch (o->tt) {
case LUA_TUSERDATA: {
case LUA_VUSERDATA: {
checkudata(g, gco2u(o));
break;
}
case LUA_TUPVAL: {
case LUA_VUPVAL: {
checkvalref(g, o, gco2upv(o)->v);
break;
}
case LUA_TTABLE: {
case LUA_VTABLE: {
checktable(g, gco2t(o));
break;
}
case LUA_TTHREAD: {
case LUA_VTHREAD: {
checkstack(g, gco2th(o));
break;
}
case LUA_TLCL: {
case LUA_VLCL: {
checkLclosure(g, gco2lcl(o));
break;
}
case LUA_TCCL: {
case LUA_VCCL: {
checkCclosure(g, gco2ccl(o));
break;
}
case LUA_TPROTO: {
case LUA_VPROTO: {
checkproto(g, gco2p(o));
break;
}
case LUA_TSHRSTR:
case LUA_TLNGSTR: {
case LUA_VSHRSTR:
case LUA_VLNGSTR: {
lua_assert(!isgray(o)); /* strings are never gray */
break;
}
@ -497,8 +497,8 @@ static void checkobject (global_State *g, GCObject *o, int maybedead,
lua_assert(isblack(o) ||
getage(o) == G_TOUCHED1 ||
getage(o) == G_OLD0 ||
o->tt == LUA_TTHREAD ||
(o->tt == LUA_TUPVAL && upisopen(gco2upv(o))));
o->tt == LUA_VTHREAD ||
(o->tt == LUA_VUPVAL && upisopen(gco2upv(o))));
}
}
checkrefs(g, o);
@ -511,11 +511,11 @@ static void checkgraylist (global_State *g, GCObject *o) {
while (o) {
lua_assert(isgray(o) || getage(o) == G_TOUCHED2);
switch (o->tt) {
case LUA_TTABLE: o = gco2t(o)->gclist; break;
case LUA_TLCL: o = gco2lcl(o)->gclist; break;
case LUA_TCCL: o = gco2ccl(o)->gclist; break;
case LUA_TTHREAD: o = gco2th(o)->gclist; break;
case LUA_TPROTO: o = gco2p(o)->gclist; break;
case LUA_VTABLE: o = gco2t(o)->gclist; break;
case LUA_VLCL: o = gco2lcl(o)->gclist; break;
case LUA_VCCL: o = gco2ccl(o)->gclist; break;
case LUA_VTHREAD: o = gco2th(o)->gclist; break;
case LUA_VPROTO: o = gco2p(o)->gclist; break;
default: lua_assert(0); /* other objects cannot be in a gray list */
}
}
@ -570,7 +570,7 @@ int lua_checkmemory (lua_State *L) {
/* check 'fixedgc' list */
for (o = g->fixedgc; o != NULL; o = o->next) {
lua_assert(o->tt == LUA_TSHRSTR && isgray(o) && getage(o) == G_OLD);
lua_assert(o->tt == LUA_VSHRSTR && isgray(o) && getage(o) == G_OLD);
}
/* check 'allgc' list */
@ -584,7 +584,7 @@ int lua_checkmemory (lua_State *L) {
for (o = g->tobefnz; o != NULL; o = o->next) {
checkobject(g, o, 0, G_NEW);
lua_assert(tofinalize(o));
lua_assert(o->tt == LUA_TUSERDATA || o->tt == LUA_TTABLE);
lua_assert(o->tt == LUA_VUSERDATA || o->tt == LUA_VTABLE);
}
return 0;
}

View File

@ -61,7 +61,7 @@ typedef struct Memcontrol {
unsigned long maxmem;
unsigned long memlimit;
unsigned long countlimit;
unsigned long objcount[LUA_NUMTAGS];
unsigned long objcount[LUA_NUMTYPES];
} Memcontrol;
LUA_API Memcontrol l_memcontrol;

2
ltm.c
View File

@ -27,7 +27,7 @@
static const char udatatypename[] = "userdata";
LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = {
LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTYPES] = {
"no value",
"nil", "boolean", udatatypename, "number",
"string", "table", "function", udatatypename, "thread",

2
ltm.h
View File

@ -59,7 +59,7 @@ typedef enum {
#define ttypename(x) luaT_typenames_[(x) + 1]
LUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTAGS];)
LUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTYPES];)
LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o);

4
lua.h
View File

@ -72,7 +72,7 @@ typedef struct lua_State lua_State;
#define LUA_TUSERDATA 7
#define LUA_TTHREAD 8
#define LUA_NUMTAGS 9
#define LUA_NUMTYPES 9
@ -412,6 +412,8 @@ LUA_API void (lua_toclose) (lua_State *L, int idx);
#define lua_getuservalue(L,idx) lua_getiuservalue(L,idx,1)
#define lua_setuservalue(L,idx) lua_setiuservalue(L,idx,1)
#define LUA_NUMTAGS LUA_NUMTYPES
/* }============================================================== */
/*

View File

@ -157,23 +157,23 @@ static void LoadConstants (LoadState *S, Proto *f) {
TValue *o = &f->k[i];
int t = LoadByte(S);
switch (t) {
case LUA_TNIL:
case LUA_VNIL:
setnilvalue(o);
break;
case LUA_TFALSE:
case LUA_VFALSE:
setbfvalue(o);
break;
case LUA_TTRUE:
case LUA_VTRUE:
setbtvalue(o);
break;
case LUA_TNUMFLT:
case LUA_VNUMFLT:
setfltvalue(o, LoadNumber(S));
break;
case LUA_TNUMINT:
case LUA_VNUMINT:
setivalue(o, LoadInteger(S));
break;
case LUA_TSHRSTR:
case LUA_TLNGSTR:
case LUA_VSHRSTR:
case LUA_VLNGSTR:
setsvalue2n(S->L, o, LoadString(S));
break;
default: lua_assert(0);

24
lvm.c
View File

@ -577,14 +577,14 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
}
/* values have same type and same variant */
switch (ttypetag(t1)) {
case LUA_TNIL: case LUA_TFALSE: case LUA_TTRUE: return 1;
case LUA_TNUMINT: return (ivalue(t1) == ivalue(t2));
case LUA_TNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));
case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
case LUA_TLCF: return fvalue(t1) == fvalue(t2);
case LUA_TSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));
case LUA_TLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));
case LUA_TUSERDATA: {
case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: return 1;
case LUA_VNUMINT: return (ivalue(t1) == ivalue(t2));
case LUA_VNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));
case LUA_VLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
case LUA_VLCF: return fvalue(t1) == fvalue(t2);
case LUA_VSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));
case LUA_VLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));
case LUA_VUSERDATA: {
if (uvalue(t1) == uvalue(t2)) return 1;
else if (L == NULL) return 0;
tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);
@ -592,7 +592,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);
break; /* will try TM */
}
case LUA_TTABLE: {
case LUA_VTABLE: {
if (hvalue(t1) == hvalue(t2)) return 1;
else if (L == NULL) return 0;
tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);
@ -680,18 +680,18 @@ void luaV_concat (lua_State *L, int total) {
void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {
const TValue *tm;
switch (ttypetag(rb)) {
case LUA_TTABLE: {
case LUA_VTABLE: {
Table *h = hvalue(rb);
tm = fasttm(L, h->metatable, TM_LEN);
if (tm) break; /* metamethod? break switch to call it */
setivalue(s2v(ra), luaH_getn(h)); /* else primitive len */
return;
}
case LUA_TSHRSTR: {
case LUA_VSHRSTR: {
setivalue(s2v(ra), tsvalue(rb)->shrlen);
return;
}
case LUA_TLNGSTR: {
case LUA_VLNGSTR: {
setivalue(s2v(ra), tsvalue(rb)->u.lnglen);
return;
}