| 333 | |
| 334 | |
| 335 | void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { |
| 336 | const TValue *tm; |
| 337 | switch (ttypenv(rb)) { |
| 338 | case LUA_TTABLE: { |
| 339 | Table *h = hvalue(rb); |
| 340 | tm = fasttm(L, h->metatable, TM_LEN); |
| 341 | if (tm) break; /* metamethod? break switch to call it */ |
| 342 | setnvalue(ra, cast_num(luaH_getn(h))); /* else primitive len */ |
| 343 | return; |
| 344 | } |
| 345 | case LUA_TSTRING: { |
| 346 | setnvalue(ra, cast_num(tsvalue(rb)->len)); |
| 347 | return; |
| 348 | } |
| 349 | default: { /* try metamethod */ |
| 350 | tm = luaT_gettmbyobj(L, rb, TM_LEN); |
| 351 | if (ttisnil(tm)) /* no metamethod? */ |
| 352 | luaG_typeerror(L, rb, "get length of"); |
| 353 | break; |
| 354 | } |
| 355 | } |
| 356 | callTM(L, tm, rb, rb, ra, 1); |
| 357 | } |
| 358 | |
| 359 | |
| 360 | void luaV_arith (lua_State *L, StkId ra, const TValue *rb, |
no test coverage detected