| 334 | |
| 335 | |
| 336 | void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { |
| 337 | const TValue *tm; |
| 338 | switch (ttypenv(rb)) { |
| 339 | case LUA_TTABLE: { |
| 340 | Table *h = hvalue(rb); |
| 341 | tm = fasttm(L, h->metatable, TM_LEN); |
| 342 | if (tm) break; /* metamethod? break switch to call it */ |
| 343 | setnvalue(ra, cast_num(luaH_getn(h))); /* else primitive len */ |
| 344 | return; |
| 345 | } |
| 346 | case LUA_TSTRING: { |
| 347 | setnvalue(ra, cast_num(tsvalue(rb)->len)); |
| 348 | return; |
| 349 | } |
| 350 | default: { /* try metamethod */ |
| 351 | tm = luaT_gettmbyobj(L, rb, TM_LEN); |
| 352 | if (ttisnil(tm)) /* no metamethod? */ |
| 353 | luaG_typeerror(L, rb, "get length of"); |
| 354 | break; |
| 355 | } |
| 356 | } |
| 357 | callTM(L, tm, rb, rb, ra, 1); |
| 358 | } |
| 359 | |
| 360 | /* |
| 361 | * luaV_div and luaV_mod patched in from Lua 5.3.2 in order to properly handle |
no test coverage detected