** Main operation 'ra' = #rb'. */
| 561 | ** Main operation 'ra' = #rb'. |
| 562 | */ |
| 563 | void luaV_objlen(lua_State *L, StkId ra, const TValue *rb) { |
| 564 | const TValue *tm; |
| 565 | switch (ttype(rb)) { |
| 566 | case LUA_TTABLE: { |
| 567 | Table *h = hvalue(rb); |
| 568 | tm = fasttm(L, h->metatable, TM_LEN); |
| 569 | if (tm) break; /* metamethod? break switch to call it */ |
| 570 | setivalue(ra, luaH_getn(h)); /* else primitive len */ |
| 571 | return; |
| 572 | } |
| 573 | case LUA_TSHRSTR: { |
| 574 | setivalue(ra, tsvalue(rb)->shrlen); |
| 575 | return; |
| 576 | } |
| 577 | case LUA_TLNGSTR: { |
| 578 | setivalue(ra, tsvalue(rb)->u.lnglen); |
| 579 | return; |
| 580 | } |
| 581 | default: { /* try metamethod */ |
| 582 | tm = luaT_gettmbyobj(L, rb, TM_LEN); |
| 583 | if (ttisnil(tm)) /* no metamethod? */ |
| 584 | luaG_typeerror(L, rb, "get length of"); |
| 585 | break; |
| 586 | } |
| 587 | } |
| 588 | luaT_callTM(L, tm, rb, rb, ra, 1); |
| 589 | } |
| 590 | |
| 591 | |
| 592 | /* |
no test coverage detected