From Lua 5.2: __len for tables. Needs -DLUAJIT_ENABLE_LUA52COMPAT.

This commit is contained in:
Mike Pall
2011-06-20 20:45:41 +02:00
parent 0f55b46b0b
commit 31d566428f
11 changed files with 5558 additions and 5317 deletions

View File

@@ -309,10 +309,19 @@ TValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o)
{
cTValue *mo = lj_meta_lookup(L, o, MM_len);
if (tvisnil(mo)) {
lj_err_optype(L, o, LJ_ERR_OPLEN);
return NULL; /* unreachable */
#ifdef LUAJIT_ENABLE_LUA52COMPAT
if (tvistab(o))
tabref(tabV(o)->metatable)->nomm |= (uint8_t)(1u<<MM_len);
else
#endif
lj_err_optype(L, o, LJ_ERR_OPLEN);
return NULL;
}
#ifdef LUAJIT_ENABLE_LUA52COMPAT
return mmcall(L, lj_cont_ra, mo, o, o);
#else
return mmcall(L, lj_cont_ra, mo, o, niltv(L));
#endif
}
/* Helper for equality comparisons. __eq metamethod. */