summaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/lapi.c b/lapi.c
index 71a9124a..5edb9fcf 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.174 2013/04/25 13:52:49 roberto Exp roberto $ 2** $Id: lapi.c,v 2.175 2013/04/26 15:39:25 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*/
@@ -271,7 +271,7 @@ LUA_API int lua_isinteger (lua_State *L, int idx) {
271 271
272 272
273LUA_API int lua_isnumber (lua_State *L, int idx) { 273LUA_API int lua_isnumber (lua_State *L, int idx) {
274 TValue n; 274 lua_Number n;
275 const TValue *o = index2addr(L, idx); 275 const TValue *o = index2addr(L, idx);
276 return tonumber(o, &n); 276 return tonumber(o, &n);
277} 277}
@@ -339,11 +339,11 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {
339 339
340 340
341LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum) { 341LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum) {
342 TValue n; 342 lua_Number n;
343 const TValue *o = index2addr(L, idx); 343 const TValue *o = index2addr(L, idx);
344 if (tonumber(o, &n)) { 344 if (tonumber(o, &n)) {
345 if (isnum) *isnum = 1; 345 if (isnum) *isnum = 1;
346 return nvalue(o); 346 return n;
347 } 347 }
348 else { 348 else {
349 if (isnum) *isnum = 0; 349 if (isnum) *isnum = 0;
@@ -353,7 +353,7 @@ LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum) {
353 353
354 354
355LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum) { 355LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum) {
356 TValue n; 356 lua_Number n;
357 const TValue *o = index2addr(L, idx); 357 const TValue *o = index2addr(L, idx);
358 if (ttisinteger(o)) { 358 if (ttisinteger(o)) {
359 if (isnum) *isnum = 1; 359 if (isnum) *isnum = 1;
@@ -361,8 +361,7 @@ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum) {
361 } 361 }
362 else if (tonumber(o, &n)) { 362 else if (tonumber(o, &n)) {
363 lua_Integer res; 363 lua_Integer res;
364 lua_Number num = nvalue(o); 364 lua_number2integer(res, n);
365 lua_number2integer(res, num);
366 if (isnum) *isnum = 1; 365 if (isnum) *isnum = 1;
367 return res; 366 return res;
368 } 367 }
@@ -374,12 +373,11 @@ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum) {
374 373
375 374
376LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *isnum) { 375LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *isnum) {
377 TValue n; 376 lua_Number n;
378 const TValue *o = index2addr(L, idx); 377 const TValue *o = index2addr(L, idx);
379 if (tonumber(o, &n)) { 378 if (tonumber(o, &n)) {
380 lua_Unsigned res; 379 lua_Unsigned res;
381 lua_Number num = nvalue(o); 380 lua_number2unsigned(res, n);
382 lua_number2unsigned(res, num);
383 if (isnum) *isnum = 1; 381 if (isnum) *isnum = 1;
384 return res; 382 return res;
385 } 383 }