** Main operation 'ra' = #rb'. */
| 402 | ** Main operation 'ra' = #rb'. |
| 403 | */ |
| 404 | void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { |
| 405 | const TValue *tm; |
| 406 | switch (ttnov(rb)) { |
| 407 | case LUA_TTABLE: { |
| 408 | Table *h = hvalue(rb); |
| 409 | tm = fasttm(L, h->metatable, TM_LEN); |
| 410 | if (tm) break; /* metamethod? break switch to call it */ |
| 411 | setivalue(ra, luaH_getn(h)); /* else primitive len */ |
| 412 | return; |
| 413 | } |
| 414 | case LUA_TSTRING: { |
| 415 | setivalue(ra, tsvalue(rb)->len); |
| 416 | return; |
| 417 | } |
| 418 | default: { /* try metamethod */ |
| 419 | tm = luaT_gettmbyobj(L, rb, TM_LEN); |
| 420 | if (ttisnil(tm)) /* no metamethod? */ |
| 421 | luaG_typeerror(L, rb, "get length of"); |
| 422 | break; |
| 423 | } |
| 424 | } |
| 425 | luaT_callTM(L, tm, rb, rb, ra, 1); |
| 426 | } |
| 427 | |
| 428 | |
| 429 | /* |
no test coverage detected