MCPcopy Create free account
hub / github.com/DFHack/dfhack / luaV_objlen

Function luaV_objlen

depends/lua/src/lvm.c:517–543  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

515** Main operation 'ra' = #rb'.
516*/
517void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {
518 const TValue *tm;
519 switch (ttype(rb)) {
520 case LUA_TTABLE: {
521 Table *h = hvalue(rb);
522 tm = fasttm(L, h->metatable, TM_LEN);
523 if (tm) break; /* metamethod? break switch to call it */
524 setivalue(ra, luaH_getn(h)); /* else primitive len */
525 return;
526 }
527 case LUA_TSHRSTR: {
528 setivalue(ra, tsvalue(rb)->shrlen);
529 return;
530 }
531 case LUA_TLNGSTR: {
532 setivalue(ra, tsvalue(rb)->u.lnglen);
533 return;
534 }
535 default: { /* try metamethod */
536 tm = luaT_gettmbyobj(L, rb, TM_LEN);
537 if (ttisnil(tm)) /* no metamethod? */
538 luaG_typeerror(L, rb, "get length of");
539 break;
540 }
541 }
542 luaT_callTM(L, tm, rb, rb, ra, 1);
543}
544
545
546/*

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_callTMFunction · 0.85

Tested by

no test coverage detected