diff options
Diffstat (limited to '')
| -rw-r--r-- | lapi.c | 12 | ||||
| -rw-r--r-- | lcode.c | 9 |
2 files changed, 12 insertions, 9 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.171 2013/03/16 21:10:18 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.172 2013/04/12 19:07:09 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 | */ |
| @@ -321,7 +321,7 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { | |||
| 321 | o2 = index2addr(L, index2); | 321 | o2 = index2addr(L, index2); |
| 322 | if (isvalid(o1) && isvalid(o2)) { | 322 | if (isvalid(o1) && isvalid(o2)) { |
| 323 | switch (op) { | 323 | switch (op) { |
| 324 | case LUA_OPEQ: i = equalobj(L, o1, o2); break; | 324 | case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break; |
| 325 | case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; | 325 | case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; |
| 326 | case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; | 326 | case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; |
| 327 | default: api_check(L, 0, "invalid option"); | 327 | default: api_check(L, 0, "invalid option"); |
| @@ -349,7 +349,11 @@ LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum) { | |||
| 349 | LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum) { | 349 | LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum) { |
| 350 | TValue n; | 350 | TValue n; |
| 351 | const TValue *o = index2addr(L, idx); | 351 | const TValue *o = index2addr(L, idx); |
| 352 | if (tonumber(o, &n)) { | 352 | if (ttisinteger(o)) { |
| 353 | if (isnum) *isnum = 1; | ||
| 354 | return ivalue(o); | ||
| 355 | } | ||
| 356 | else if (tonumber(o, &n)) { | ||
| 353 | lua_Integer res; | 357 | lua_Integer res; |
| 354 | lua_Number num = nvalue(o); | 358 | lua_Number num = nvalue(o); |
| 355 | lua_number2integer(res, num); | 359 | lua_number2integer(res, num); |
| @@ -482,7 +486,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | |||
| 482 | 486 | ||
| 483 | LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { | 487 | LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { |
| 484 | lua_lock(L); | 488 | lua_lock(L); |
| 485 | setnvalue(L->top, cast_num(n)); | 489 | setivalue(L->top, cast_num(n)); |
| 486 | api_incr_top(L); | 490 | api_incr_top(L); |
| 487 | lua_unlock(L); | 491 | lua_unlock(L); |
| 488 | } | 492 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 2.61 2012/08/14 18:12:34 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.62 2012/08/16 17:34:28 roberto Exp $ |
| 3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -293,9 +293,8 @@ static int addk (FuncState *fs, TValue *key, TValue *v) { | |||
| 293 | TValue *idx = luaH_set(L, fs->h, key); | 293 | TValue *idx = luaH_set(L, fs->h, key); |
| 294 | Proto *f = fs->f; | 294 | Proto *f = fs->f; |
| 295 | int k, oldsize; | 295 | int k, oldsize; |
| 296 | if (ttisnumber(idx)) { | 296 | if (ttisinteger(idx)) { |
| 297 | lua_Number n = nvalue(idx); | 297 | k = ivalue(idx); |
| 298 | lua_number2int(k, n); | ||
| 299 | if (luaV_rawequalobj(&f->k[k], v)) | 298 | if (luaV_rawequalobj(&f->k[k], v)) |
| 300 | return k; | 299 | return k; |
| 301 | /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0"); | 300 | /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0"); |
| @@ -306,7 +305,7 @@ static int addk (FuncState *fs, TValue *key, TValue *v) { | |||
| 306 | k = fs->nk; | 305 | k = fs->nk; |
| 307 | /* numerical value does not need GC barrier; | 306 | /* numerical value does not need GC barrier; |
| 308 | table has no metatable, so it does not need to invalidate cache */ | 307 | table has no metatable, so it does not need to invalidate cache */ |
| 309 | setnvalue(idx, cast_num(k)); | 308 | setivalue(idx, k); |
| 310 | luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants"); | 309 | luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants"); |
| 311 | while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); | 310 | while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); |
| 312 | setobj(L, &f->k[k], v); | 311 | setobj(L, &f->k[k], v); |
