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