** Main operation 'ra' = #rb'. */
| 515 | ** Main operation 'ra' = #rb'. |
| 516 | */ |
| 517 | void 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 | /* |
no test coverage detected