** Main operation 'ra = #rb'. */
| 681 | ** Main operation 'ra = #rb'. |
| 682 | */ |
| 683 | void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { |
| 684 | const TValue *tm; |
| 685 | switch (ttypetag(rb)) { |
| 686 | case LUA_VTABLE: { |
| 687 | Table *h = hvalue(rb); |
| 688 | tm = fasttm(L, h->metatable, TM_LEN); |
| 689 | if (tm) break; /* metamethod? break switch to call it */ |
| 690 | setivalue(s2v(ra), luaH_getn(h)); /* else primitive len */ |
| 691 | return; |
| 692 | } |
| 693 | case LUA_VSHRSTR: { |
| 694 | setivalue(s2v(ra), tsvalue(rb)->shrlen); |
| 695 | return; |
| 696 | } |
| 697 | case LUA_VLNGSTR: { |
| 698 | setivalue(s2v(ra), tsvalue(rb)->u.lnglen); |
| 699 | return; |
| 700 | } |
| 701 | default: { /* try metamethod */ |
| 702 | tm = luaT_gettmbyobj(L, rb, TM_LEN); |
| 703 | if (l_unlikely(notm(tm))) /* no metamethod? */ |
| 704 | luaG_typeerror(L, rb, "get length of"); |
| 705 | break; |
| 706 | } |
| 707 | } |
| 708 | luaT_callTMres(L, tm, rb, rb, ra); |
| 709 | } |
| 710 | |
| 711 | |
| 712 | /* |
no test coverage detected