** Main operation 'ra = #rb'. */
| 729 | ** Main operation 'ra = #rb'. |
| 730 | */ |
| 731 | void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { |
| 732 | const TValue *tm; |
| 733 | switch (ttypetag(rb)) { |
| 734 | case LUA_VTABLE: { |
| 735 | Table *h = hvalue(rb); |
| 736 | tm = fasttm(L, h->metatable, TM_LEN); |
| 737 | if (tm) break; /* metamethod? break switch to call it */ |
| 738 | setivalue(s2v(ra), l_castU2S(luaH_getn(L, h))); /* else primitive len */ |
| 739 | return; |
| 740 | } |
| 741 | case LUA_VSHRSTR: { |
| 742 | setivalue(s2v(ra), tsvalue(rb)->shrlen); |
| 743 | return; |
| 744 | } |
| 745 | case LUA_VLNGSTR: { |
| 746 | setivalue(s2v(ra), cast_st2S(tsvalue(rb)->u.lnglen)); |
| 747 | return; |
| 748 | } |
| 749 | default: { /* try metamethod */ |
| 750 | tm = luaT_gettmbyobj(L, rb, TM_LEN); |
| 751 | if (l_unlikely(notm(tm))) /* no metamethod? */ |
| 752 | luaG_typeerror(L, rb, "get length of"); |
| 753 | break; |
| 754 | } |
| 755 | } |
| 756 | luaT_callTMres(L, tm, rb, rb, ra); |
| 757 | } |
| 758 | |
| 759 | |
| 760 | /* |
no test coverage detected