From Lua 5.2: __len for tables. Needs -DLUAJIT_ENABLE_LUA52COMPAT.
This commit is contained in:
@@ -767,9 +767,16 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| mov CARG1, L
|
||||
| str PC, SAVE_PC
|
||||
| bl extern lj_meta_len // (lua_State *L, TValue *o)
|
||||
| // Returns TValue * (metamethod base).
|
||||
| // Returns NULL (retry) or TValue * (metamethod base).
|
||||
| IOS ldr BASE, L->base
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
| cmp CRET1, #0
|
||||
| bne ->vmeta_binop // Binop call for compatibility.
|
||||
| ldr TAB:CARG1, [BASE, RC]
|
||||
| b ->BC_LEN_Z
|
||||
#else
|
||||
| b ->vmeta_binop // Binop call for compatibility.
|
||||
#endif
|
||||
|
|
||||
|//-- Call metamethod ----------------------------------------------------
|
||||
|
|
||||
@@ -2546,11 +2553,25 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
| ins_next3
|
||||
|2:
|
||||
| checktab CARG2, ->vmeta_len
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
| ldr TAB:CARG3, TAB:CARG1->metatable
|
||||
| cmp TAB:CARG3, #0
|
||||
| bne >9
|
||||
|3:
|
||||
#endif
|
||||
|->BC_LEN_Z:
|
||||
| IOS mov RC, BASE
|
||||
| bl extern lj_tab_len // (GCtab *t)
|
||||
| // Returns uint32_t (but less than 2^31).
|
||||
| IOS mov BASE, RC
|
||||
| b <1
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
|9:
|
||||
| ldrb CARG4, TAB:CARG3->nomm
|
||||
| tst CARG4, #1<<MM_len
|
||||
| bne <3 // 'no __len' flag set: done.
|
||||
| b ->vmeta_len
|
||||
#endif
|
||||
break;
|
||||
|
||||
/* -- Binary ops -------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user