MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / luaV_objlen

Function luaV_objlen

3rd/lua-5.4.3/src/lvm.c:683–709  ·  view source on GitHub ↗

** Main operation 'ra = #rb'. */

Source from the content-addressed store, hash-verified

681** Main operation 'ra = #rb'.
682*/
683void 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/*

Callers 2

luaV_executeFunction · 0.85
lua_lenFunction · 0.85

Calls 4

luaH_getnFunction · 0.85
luaT_gettmbyobjFunction · 0.85
luaG_typeerrorFunction · 0.85
luaT_callTMresFunction · 0.85

Tested by

no test coverage detected