** main search function */
| 541 | ** main search function |
| 542 | */ |
| 543 | static const TValue *luaH_get_int (Table *t, const TValue *key, |
| 544 | TValue **foundkey) { |
| 545 | lua_Number num; |
| 546 | int type = ttype(key); |
| 547 | switch (type) { |
| 548 | case LUA_TNIL: return luaO_nilobject; |
| 549 | case LUA_TSTRING: return luaH_getstr_int(t, rawtsvalue(key), foundkey); |
| 550 | case LUA_TUSERDATA: |
| 551 | case LUA_TNUMBER: { |
| 552 | int isnum = 1; |
| 553 | if (type == LUA_TUSERDATA) { |
| 554 | void *raw = rawuvalue(key) + 1; /* lua_topointer */ |
| 555 | if (luabb_hashinfo(raw, &num, NULL, NULL) != Numeric) |
| 556 | isnum = 0; |
| 557 | } else { |
| 558 | num = nvalue(key); |
| 559 | } |
| 560 | if (isnum) { |
| 561 | int k; |
| 562 | lua_number2int(k, num); |
| 563 | if (luai_numeq(cast_num(k), num)) /* index is int? */ |
| 564 | return luaH_getnum_int(t, k, foundkey); /* use specialized version */ |
| 565 | } |
| 566 | /* else go through */ |
| 567 | } |
| 568 | default: { |
| 569 | Node *n = mainposition(t, key); |
| 570 | do { /* check whether `key' is somewhere in the chain */ |
| 571 | if (luaO_rawequalObj(key2tval(n), key)) { |
| 572 | if (foundkey) |
| 573 | *foundkey = key2tval(n); |
| 574 | return gval(n); /* that's it */ |
| 575 | } |
| 576 | n = gnext(n); |
| 577 | } while (n); |
| 578 | return luaO_nilobject; |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | |
| 584 | const TValue *luaH_get(Table *t, const TValue *key) { |
no test coverage detected