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