diff options
Diffstat (limited to 'ltable.c')
| -rw-r--r-- | ltable.c | 21 |
1 files changed, 13 insertions, 8 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.87 2014/04/15 14:28:20 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.88 2014/04/15 16:32:49 roberto Exp roberto $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -67,12 +67,6 @@ | |||
| 67 | #define hashpointer(t,p) hashmod(t, IntPoint(p)) | 67 | #define hashpointer(t,p) hashmod(t, IntPoint(p)) |
| 68 | 68 | ||
| 69 | 69 | ||
| 70 | /* checks whether a float has a value representable as a lua_Integer | ||
| 71 | (and does the conversion if so) */ | ||
| 72 | #define numisinteger(x,i) \ | ||
| 73 | (((x) == l_floor(x)) && luaV_numtointeger(x, i)) | ||
| 74 | |||
| 75 | |||
| 76 | #define dummynode (&dummynode_) | 70 | #define dummynode (&dummynode_) |
| 77 | 71 | ||
| 78 | #define isdummy(n) ((n) == dummynode) | 72 | #define isdummy(n) ((n) == dummynode) |
| @@ -84,6 +78,17 @@ static const Node dummynode_ = { | |||
| 84 | 78 | ||
| 85 | 79 | ||
| 86 | /* | 80 | /* |
| 81 | ** Checks whether a float has a value representable as a lua_Integer | ||
| 82 | ** (and does the conversion if so) | ||
| 83 | */ | ||
| 84 | static int numisinteger (lua_Number x, lua_Integer *p) { | ||
| 85 | if ((x) == l_floor(x)) /* integral value? */ | ||
| 86 | return lua_numtointeger(x, p); /* try as an integer */ | ||
| 87 | else return 0; | ||
| 88 | } | ||
| 89 | |||
| 90 | |||
| 91 | /* | ||
| 87 | ** hash for floating-point numbers | 92 | ** hash for floating-point numbers |
| 88 | */ | 93 | */ |
| 89 | static Node *hashfloat (const Table *t, lua_Number n) { | 94 | static Node *hashfloat (const Table *t, lua_Number n) { |
| @@ -424,7 +429,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { | |||
| 424 | if (luai_numisnan(n)) | 429 | if (luai_numisnan(n)) |
| 425 | luaG_runerror(L, "table index is NaN"); | 430 | luaG_runerror(L, "table index is NaN"); |
| 426 | if (numisinteger(n, &k)) { /* index is int? */ | 431 | if (numisinteger(n, &k)) { /* index is int? */ |
| 427 | setivalue(&aux, k); | 432 | setivalue(&aux, k); |
| 428 | key = &aux; /* insert it as an integer */ | 433 | key = &aux; /* insert it as an integer */ |
| 429 | } | 434 | } |
| 430 | } | 435 | } |
