diff options
| -rw-r--r-- | lapi.c | 6 | ||||
| -rw-r--r-- | ltable.c | 34 | ||||
| -rw-r--r-- | ltable.h | 7 | ||||
| -rw-r--r-- | lua.h | 6 |
4 files changed, 29 insertions, 24 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.173 2013/04/15 15:43:34 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.174 2013/04/25 13:52:49 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -656,7 +656,7 @@ LUA_API void lua_rawget (lua_State *L, int idx) { | |||
| 656 | } | 656 | } |
| 657 | 657 | ||
| 658 | 658 | ||
| 659 | LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { | 659 | LUA_API void lua_rawgeti (lua_State *L, int idx, lua_Integer n) { |
| 660 | StkId t; | 660 | StkId t; |
| 661 | lua_lock(L); | 661 | lua_lock(L); |
| 662 | t = index2addr(L, idx); | 662 | t = index2addr(L, idx); |
| @@ -791,7 +791,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) { | |||
| 791 | } | 791 | } |
| 792 | 792 | ||
| 793 | 793 | ||
| 794 | LUA_API void lua_rawseti (lua_State *L, int idx, int n) { | 794 | LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { |
| 795 | StkId t; | 795 | StkId t; |
| 796 | lua_lock(L); | 796 | lua_lock(L); |
| 797 | api_checknelems(L, 1); | 797 | api_checknelems(L, 1); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.71 2012/05/23 15:37:09 roberto Exp $ | 2 | ** $Id: ltable.c,v 2.73 2013/04/15 15:44:46 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 | */ |
| @@ -123,9 +123,9 @@ static Node *mainposition (const Table *t, const TValue *key) { | |||
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | 125 | ||
| 126 | static int numisint (lua_Number n, int *p) { | 126 | static int numisint (lua_Number n, lua_Integer *p) { |
| 127 | int k; | 127 | lua_Integer k; |
| 128 | lua_number2int(k, n); | 128 | lua_number2integer(k, n); |
| 129 | if (luai_numeq(cast_num(k), n)) { /* 'k' is int? */ | 129 | if (luai_numeq(cast_num(k), n)) { /* 'k' is int? */ |
| 130 | *p = k; | 130 | *p = k; |
| 131 | return 1; | 131 | return 1; |
| @@ -139,8 +139,12 @@ static int numisint (lua_Number n, int *p) { | |||
| 139 | ** the array part of the table, -1 otherwise. | 139 | ** the array part of the table, -1 otherwise. |
| 140 | */ | 140 | */ |
| 141 | static int arrayindex (const TValue *key) { | 141 | static int arrayindex (const TValue *key) { |
| 142 | if (ttisinteger(key)) return ivalue(key); | 142 | if (ttisinteger(key)) { |
| 143 | else return -1; /* `key' did not match some condition */ | 143 | lua_Integer k = ivalue(key); |
| 144 | if (0 < k && k <= MAXASIZE) /* is `key' an appropriate array index? */ | ||
| 145 | return cast_int(k); | ||
| 146 | } | ||
| 147 | return -1; /* `key' did not match some condition */ | ||
| 144 | } | 148 | } |
| 145 | 149 | ||
| 146 | 150 | ||
| @@ -225,7 +229,7 @@ static int computesizes (int nums[], int *narray) { | |||
| 225 | 229 | ||
| 226 | static int countint (const TValue *key, int *nums) { | 230 | static int countint (const TValue *key, int *nums) { |
| 227 | int k = arrayindex(key); | 231 | int k = arrayindex(key); |
| 228 | if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */ | 232 | if (k > 0) { /* is `key' an appropriate array index? */ |
| 229 | nums[luaO_ceillog2(k)]++; /* count as such */ | 233 | nums[luaO_ceillog2(k)]++; /* count as such */ |
| 230 | return 1; | 234 | return 1; |
| 231 | } | 235 | } |
| @@ -416,7 +420,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { | |||
| 416 | if (ttisnil(key)) luaG_runerror(L, "table index is nil"); | 420 | if (ttisnil(key)) luaG_runerror(L, "table index is nil"); |
| 417 | else if (ttisfloat(key)) { | 421 | else if (ttisfloat(key)) { |
| 418 | lua_Number n = fltvalue(key); | 422 | lua_Number n = fltvalue(key); |
| 419 | int k; | 423 | lua_Integer k; |
| 420 | if (luai_numisnan(L, n)) | 424 | if (luai_numisnan(L, n)) |
| 421 | luaG_runerror(L, "table index is NaN"); | 425 | luaG_runerror(L, "table index is NaN"); |
| 422 | if (numisint(n, &k)) { /* index is int? */ | 426 | if (numisint(n, &k)) { /* index is int? */ |
| @@ -460,10 +464,10 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { | |||
| 460 | /* | 464 | /* |
| 461 | ** search function for integers | 465 | ** search function for integers |
| 462 | */ | 466 | */ |
| 463 | const TValue *luaH_getint (Table *t, int key) { | 467 | const TValue *luaH_getint (Table *t, lua_Integer key) { |
| 464 | /* (1 <= key && key <= t->sizearray) */ | 468 | /* (1 <= key && key <= t->sizearray) */ |
| 465 | if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) | 469 | if (cast_unsigned(key - 1) < cast_unsigned(t->sizearray)) |
| 466 | return &t->array[key-1]; | 470 | return &t->array[key - 1]; |
| 467 | else { | 471 | else { |
| 468 | Node *n = hashint(t, key); | 472 | Node *n = hashint(t, key); |
| 469 | do { /* check whether `key' is somewhere in the chain */ | 473 | do { /* check whether `key' is somewhere in the chain */ |
| @@ -500,7 +504,7 @@ const TValue *luaH_get (Table *t, const TValue *key) { | |||
| 500 | case LUA_TNUMINT: return luaH_getint(t, ivalue(key)); | 504 | case LUA_TNUMINT: return luaH_getint(t, ivalue(key)); |
| 501 | case LUA_TNIL: return luaO_nilobject; | 505 | case LUA_TNIL: return luaO_nilobject; |
| 502 | case LUA_TNUMFLT: { | 506 | case LUA_TNUMFLT: { |
| 503 | int k; | 507 | lua_Integer k; |
| 504 | if (numisint(fltvalue(key), &k)) /* index is int? */ | 508 | if (numisint(fltvalue(key), &k)) /* index is int? */ |
| 505 | return luaH_getint(t, k); /* use specialized version */ | 509 | return luaH_getint(t, k); /* use specialized version */ |
| 506 | /* else go through */ | 510 | /* else go through */ |
| @@ -530,7 +534,7 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { | |||
| 530 | } | 534 | } |
| 531 | 535 | ||
| 532 | 536 | ||
| 533 | void luaH_setint (lua_State *L, Table *t, int key, TValue *value) { | 537 | void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) { |
| 534 | const TValue *p = luaH_getint(t, key); | 538 | const TValue *p = luaH_getint(t, key); |
| 535 | TValue *cell; | 539 | TValue *cell; |
| 536 | if (p != luaO_nilobject) | 540 | if (p != luaO_nilobject) |
| @@ -550,13 +554,13 @@ static int unbound_search (Table *t, unsigned int j) { | |||
| 550 | /* find `i' and `j' such that i is present and j is not */ | 554 | /* find `i' and `j' such that i is present and j is not */ |
| 551 | while (!ttisnil(luaH_getint(t, j))) { | 555 | while (!ttisnil(luaH_getint(t, j))) { |
| 552 | i = j; | 556 | i = j; |
| 553 | j *= 2; | 557 | if (j > cast(unsigned int, MAX_INT)/2) { /* overflow? */ |
| 554 | if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ | ||
| 555 | /* table was built with bad purposes: resort to linear search */ | 558 | /* table was built with bad purposes: resort to linear search */ |
| 556 | i = 1; | 559 | i = 1; |
| 557 | while (!ttisnil(luaH_getint(t, i))) i++; | 560 | while (!ttisnil(luaH_getint(t, i))) i++; |
| 558 | return i - 1; | 561 | return i - 1; |
| 559 | } | 562 | } |
| 563 | j *= 2; | ||
| 560 | } | 564 | } |
| 561 | /* now do a binary search between them */ | 565 | /* now do a binary search between them */ |
| 562 | while (j - i > 1) { | 566 | while (j - i > 1) { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.h,v 2.15 2011/08/09 20:58:29 roberto Exp roberto $ | 2 | ** $Id: ltable.h,v 2.16 2011/08/17 20:26:47 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 | */ |
| @@ -18,8 +18,9 @@ | |||
| 18 | #define invalidateTMcache(t) ((t)->flags = 0) | 18 | #define invalidateTMcache(t) ((t)->flags = 0) |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | LUAI_FUNC const TValue *luaH_getint (Table *t, int key); | 21 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); |
| 22 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value); | 22 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, |
| 23 | TValue *value); | ||
| 23 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); | 24 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); |
| 24 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); | 25 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); |
| 25 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); | 26 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.286 2013/04/25 13:52:49 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.287 2013/04/26 13:07:53 roberto Exp roberto $ |
| 3 | ** Lua - A Scripting Language | 3 | ** Lua - A Scripting Language |
| 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) | 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) |
| 5 | ** See Copyright Notice at the end of this file | 5 | ** See Copyright Notice at the end of this file |
| @@ -226,7 +226,7 @@ LUA_API void (lua_getglobal) (lua_State *L, const char *var); | |||
| 226 | LUA_API void (lua_gettable) (lua_State *L, int idx); | 226 | LUA_API void (lua_gettable) (lua_State *L, int idx); |
| 227 | LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); | 227 | LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); |
| 228 | LUA_API void (lua_rawget) (lua_State *L, int idx); | 228 | LUA_API void (lua_rawget) (lua_State *L, int idx); |
| 229 | LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); | 229 | LUA_API void (lua_rawgeti) (lua_State *L, int idx, lua_Integer n); |
| 230 | LUA_API void (lua_rawgetp) (lua_State *L, int idx, const void *p); | 230 | LUA_API void (lua_rawgetp) (lua_State *L, int idx, const void *p); |
| 231 | LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); | 231 | LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); |
| 232 | LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); | 232 | LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); |
| @@ -241,7 +241,7 @@ LUA_API void (lua_setglobal) (lua_State *L, const char *var); | |||
| 241 | LUA_API void (lua_settable) (lua_State *L, int idx); | 241 | LUA_API void (lua_settable) (lua_State *L, int idx); |
| 242 | LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); | 242 | LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); |
| 243 | LUA_API void (lua_rawset) (lua_State *L, int idx); | 243 | LUA_API void (lua_rawset) (lua_State *L, int idx); |
| 244 | LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); | 244 | LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n); |
| 245 | LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p); | 245 | LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p); |
| 246 | LUA_API int (lua_setmetatable) (lua_State *L, int objindex); | 246 | LUA_API int (lua_setmetatable) (lua_State *L, int objindex); |
| 247 | LUA_API void (lua_setuservalue) (lua_State *L, int idx); | 247 | LUA_API void (lua_setuservalue) (lua_State *L, int idx); |
