aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-06-14 15:34:49 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-06-14 15:34:49 -0300
commit138e69cc55fb3e808206c3532b26063baa19d93b (patch)
tree42a25cab4a56fb0adbbcd8e51cf7b76c0e013592 /lauxlib.c
parent53210d7e5b55494824a86d63e7f5f6f7ea1d8c17 (diff)
downloadlua-138e69cc55fb3e808206c3532b26063baa19d93b.tar.gz
lua-138e69cc55fb3e808206c3532b26063baa19d93b.tar.bz2
lua-138e69cc55fb3e808206c3532b26063baa19d93b.zip
correct error message for floating-point values out of (integer) range
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 7cb6821e..17fc962c 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.250 2013/06/04 19:36:42 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.251 2013/06/14 18:12:53 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -386,11 +386,22 @@ LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {
386} 386}
387 387
388 388
389static void interror (lua_State *L, int narg) {
390 if (lua_type(L, narg) == LUA_TNUMBER) {
391 assert(!lua_isinteger(L, narg));
392 luaL_argerror(L, narg, "float value out of range");
393 }
394 else
395 tag_error(L, narg, LUA_TNUMBER);
396}
397
398
389LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { 399LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) {
390 int isnum; 400 int isnum;
391 lua_Integer d = lua_tointegerx(L, narg, &isnum); 401 lua_Integer d = lua_tointegerx(L, narg, &isnum);
392 if (!isnum) 402 if (!isnum) {
393 tag_error(L, narg, LUA_TNUMBER); 403 interror(L, narg);
404 }
394 return d; 405 return d;
395} 406}
396 407
@@ -399,7 +410,7 @@ LUALIB_API lua_Unsigned luaL_checkunsigned (lua_State *L, int narg) {
399 int isnum; 410 int isnum;
400 lua_Unsigned d = lua_tounsignedx(L, narg, &isnum); 411 lua_Unsigned d = lua_tounsignedx(L, narg, &isnum);
401 if (!isnum) 412 if (!isnum)
402 tag_error(L, narg, LUA_TNUMBER); 413 interror(L, narg);
403 return d; 414 return d;
404} 415}
405 416