From a2031547aafbb07f6284cd10704435db23d9db60 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 8 Feb 2017 07:38:03 +0100 Subject: callstatus, OP_LE, OP_JMP, tests use L.top --- src/lobject.js | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'src/lobject.js') diff --git a/src/lobject.js b/src/lobject.js index 4cc8c4e..3781623 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -12,6 +12,96 @@ class TValue { this.metatable = null; } + /* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */ + ttype() { + return this.type & 0x3F; + } + + /* type tag of a TValue with no variants (bits 0-3) */ + ttnov() { + return this.type & 0x0F; + } + + checktag(t) { + return this.type === t; + } + + checktype(t) { + return this.ttnov() === t; + } + + ttisnumber() { + return this.checktype(CT.LUA_TNUMBER); + } + + ttisfloat() { + return this.checktag(CT.LUA_TNUMFLT); + } + + ttisinteger() { + return this.checktag(CT.LUA_TNUMINT); + } + + ttisnil() { + return this.checktag(CT.LUA_TNIL); + } + + ttisboolean() { + return this.checktag(CT.LUA_TBOOLEAN); + } + + ttislightuserdata() { + return this.checktag(CT.LUA_TLIGHTUSERDATA); + } + + ttisstring() { + return this.checktype(CT.LUA_TSTRING); + } + + ttisshrstring() { + return this.checktag(ctb(CT.LUA_TSHRSTR)); + } + + ttislngstring() { + return this.checktag(ctb(CT.LUA_TLNGSTR)); + } + + ttistable() { + return this.checktag(ctb(CT.LUA_TTABLE)); + } + + ttisfunction() { + return this.checktype(CT.LUA_TFUNCTION); + } + + ttisclosure() { + return (this.type & 0x1F) === CT.LUA_TFUNCTION; + } + + ttisCclosure() { + return this.checktag(ctb(CT.LUA_TCCL)); + } + + ttisLclosure() { + return this.checktag(ctb(CT.LUA_TLCL)); + } + + ttislcf() { + return this.checktag(CT.LUA_TLCF); + } + + ttisfulluserdata() { + return this.checktag(ctb(CT.LUA_TUSERDATA)); + } + + ttisthread() { + return this.checktag(ctb(CT.LUA_TTHREAD)); + } + + ttisdeadkey() { + return this.checktag(CT.LUA_TDEADKEY); + } + } -- cgit v1.2.3-54-g00ecf