** Main operation 'ra = #rb'. */
| 698 | ** Main operation 'ra = #rb'. |
| 699 | */ |
| 700 | void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { |
| 701 | const TValue *tm; |
| 702 | switch (ttypetag(rb)) { |
| 703 | case LUA_VTABLE: { |
| 704 | Table *h = hvalue(rb); |
| 705 | tm = fasttm(L, h->metatable, TM_LEN); |
| 706 | if (tm) break; /* metamethod? break switch to call it */ |
| 707 | setivalue(s2v(ra), luaH_getn(h)); /* else primitive len */ |
| 708 | return; |
| 709 | } |
| 710 | case LUA_VSHRSTR: { |
| 711 | setivalue(s2v(ra), tsvalue(rb)->shrlen); |
| 712 | return; |
| 713 | } |
| 714 | case LUA_VLNGSTR: { |
| 715 | setivalue(s2v(ra), tsvalue(rb)->u.lnglen); |
| 716 | return; |
| 717 | } |
| 718 | default: { /* try metamethod */ |
| 719 | tm = luaT_gettmbyobj(L, rb, TM_LEN); |
| 720 | if (l_unlikely(notm(tm))) /* no metamethod? */ |
| 721 | luaG_typeerror(L, rb, "get length of"); |
| 722 | break; |
| 723 | } |
| 724 | } |
| 725 | luaT_callTMres(L, tm, rb, rb, ra); |
| 726 | } |
| 727 | |
| 728 | |
| 729 | /* |
no test coverage detected