summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lauxlib.c8
-rw-r--r--liolib.c8
-rw-r--r--lmathlib.c11
-rw-r--r--lstrlib.c16
-rw-r--r--luaconf.h16
5 files changed, 35 insertions, 24 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 35ad7846..7b14ca4d 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.287 2016/12/04 20:09:45 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.288 2016/12/04 20:17:24 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*/
@@ -816,9 +816,9 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
816 switch (lua_type(L, idx)) { 816 switch (lua_type(L, idx)) {
817 case LUA_TNUMBER: { 817 case LUA_TNUMBER: {
818 if (lua_isinteger(L, idx)) 818 if (lua_isinteger(L, idx))
819 lua_pushfstring(L, "%I", lua_tointeger(L, idx)); 819 lua_pushfstring(L, "%I", (LUAI_UACINT)lua_tointeger(L, idx));
820 else 820 else
821 lua_pushfstring(L, "%f", lua_tonumber(L, idx)); 821 lua_pushfstring(L, "%f", (LUAI_UACNUMBER)lua_tonumber(L, idx));
822 break; 822 break;
823 } 823 }
824 case LUA_TSTRING: 824 case LUA_TSTRING:
@@ -1038,6 +1038,6 @@ LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) {
1038 luaL_error(L, "multiple Lua VMs detected"); 1038 luaL_error(L, "multiple Lua VMs detected");
1039 else if (*v != ver) 1039 else if (*v != ver)
1040 luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f", 1040 luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f",
1041 ver, *v); 1041 (LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)*v);
1042} 1042}
1043 1043
diff --git a/liolib.c b/liolib.c
index db2f01c2..8491edca 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 2.149 2016/05/02 14:03:19 roberto Exp roberto $ 2** $Id: liolib.c,v 2.150 2016/09/01 16:14:56 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -619,8 +619,10 @@ static int g_write (lua_State *L, FILE *f, int arg) {
619 if (lua_type(L, arg) == LUA_TNUMBER) { 619 if (lua_type(L, arg) == LUA_TNUMBER) {
620 /* optimization: could be done exactly as for strings */ 620 /* optimization: could be done exactly as for strings */
621 int len = lua_isinteger(L, arg) 621 int len = lua_isinteger(L, arg)
622 ? fprintf(f, LUA_INTEGER_FMT, lua_tointeger(L, arg)) 622 ? fprintf(f, LUA_INTEGER_FMT,
623 : fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)); 623 (LUAI_UACINT)lua_tointeger(L, arg))
624 : fprintf(f, LUA_NUMBER_FMT,
625 (LUAI_UACNUMBER)lua_tonumber(L, arg));
624 status = status && (len > 0); 626 status = status && (len > 0);
625 } 627 }
626 else { 628 else {
diff --git a/lmathlib.c b/lmathlib.c
index 8c9627c2..4cf90ce4 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.116 2015/06/26 19:30:32 roberto Exp $ 2** $Id: lmathlib.c,v 1.117 2015/10/02 15:39:23 roberto Exp roberto $
3** Standard mathematical library 3** Standard mathematical library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -184,10 +184,13 @@ static int math_log (lua_State *L) {
184 else { 184 else {
185 lua_Number base = luaL_checknumber(L, 2); 185 lua_Number base = luaL_checknumber(L, 2);
186#if !defined(LUA_USE_C89) 186#if !defined(LUA_USE_C89)
187 if (base == 2.0) res = l_mathop(log2)(x); else 187 if (base == l_mathop(2.0))
188 res = l_mathop(log2)(x); else
188#endif 189#endif
189 if (base == 10.0) res = l_mathop(log10)(x); 190 if (base == l_mathop(10.0))
190 else res = l_mathop(log)(x)/l_mathop(log)(base); 191 res = l_mathop(log10)(x);
192 else
193 res = l_mathop(log)(x)/l_mathop(log)(base);
191 } 194 }
192 lua_pushnumber(L, res); 195 lua_pushnumber(L, res);
193 return 1; 196 return 1;
diff --git a/lstrlib.c b/lstrlib.c
index 8d3f305c..1b56e2b0 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.251 2016/05/20 14:13:21 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.252 2016/06/27 13:15:08 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -839,11 +839,12 @@ static lua_Number adddigit (char *buff, int n, lua_Number x) {
839 839
840 840
841static int num2straux (char *buff, int sz, lua_Number x) { 841static int num2straux (char *buff, int sz, lua_Number x) {
842 if (x != x || x == HUGE_VAL || x == -HUGE_VAL) /* inf or NaN? */ 842 /* if 'inf' or 'NaN', format it like '%g' */
843 return l_sprintf(buff, sz, LUA_NUMBER_FMT, x); /* equal to '%g' */ 843 if (x != x || x == (lua_Number)HUGE_VAL || x == -(lua_Number)HUGE_VAL)
844 return l_sprintf(buff, sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)x);
844 else if (x == 0) { /* can be -0... */ 845 else if (x == 0) { /* can be -0... */
845 /* create "0" or "-0" followed by exponent */ 846 /* create "0" or "-0" followed by exponent */
846 return l_sprintf(buff, sz, LUA_NUMBER_FMT "x0p+0", x); 847 return l_sprintf(buff, sz, LUA_NUMBER_FMT "x0p+0", (LUAI_UACNUMBER)x);
847 } 848 }
848 else { 849 else {
849 int e; 850 int e;
@@ -960,7 +961,7 @@ static void addliteral (lua_State *L, luaL_Buffer *b, int arg) {
960 const char *format = (n == LUA_MININTEGER) /* corner case? */ 961 const char *format = (n == LUA_MININTEGER) /* corner case? */
961 ? "0x%" LUA_INTEGER_FRMLEN "x" /* use hexa */ 962 ? "0x%" LUA_INTEGER_FRMLEN "x" /* use hexa */
962 : LUA_INTEGER_FMT; /* else use default format */ 963 : LUA_INTEGER_FMT; /* else use default format */
963 nb = l_sprintf(buff, MAX_ITEM, format, n); 964 nb = l_sprintf(buff, MAX_ITEM, format, (LUAI_UACINT)n);
964 } 965 }
965 luaL_addsize(b, nb); 966 luaL_addsize(b, nb);
966 break; 967 break;
@@ -1041,7 +1042,7 @@ static int str_format (lua_State *L) {
1041 case 'o': case 'u': case 'x': case 'X': { 1042 case 'o': case 'u': case 'x': case 'X': {
1042 lua_Integer n = luaL_checkinteger(L, arg); 1043 lua_Integer n = luaL_checkinteger(L, arg);
1043 addlenmod(form, LUA_INTEGER_FRMLEN); 1044 addlenmod(form, LUA_INTEGER_FRMLEN);
1044 nb = l_sprintf(buff, MAX_ITEM, form, n); 1045 nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACINT)n);
1045 break; 1046 break;
1046 } 1047 }
1047 case 'a': case 'A': 1048 case 'a': case 'A':
@@ -1051,8 +1052,9 @@ static int str_format (lua_State *L) {
1051 break; 1052 break;
1052 case 'e': case 'E': case 'f': 1053 case 'e': case 'E': case 'f':
1053 case 'g': case 'G': { 1054 case 'g': case 'G': {
1055 lua_Number n = luaL_checknumber(L, arg);
1054 addlenmod(form, LUA_NUMBER_FRMLEN); 1056 addlenmod(form, LUA_NUMBER_FRMLEN);
1055 nb = l_sprintf(buff, MAX_ITEM, form, luaL_checknumber(L, arg)); 1057 nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACNUMBER)n);
1056 break; 1058 break;
1057 } 1059 }
1058 case 'q': { 1060 case 'q': {
diff --git a/luaconf.h b/luaconf.h
index b9878d41..7c7e2c0d 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luaconf.h,v 1.256 2016/07/18 17:55:59 roberto Exp roberto $ 2** $Id: luaconf.h,v 1.257 2016/08/22 17:21:12 roberto Exp roberto $
3** Configuration file for Lua 3** Configuration file for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -416,7 +416,7 @@
416 416
417/* 417/*
418@@ LUA_NUMBER is the floating-point type used by Lua. 418@@ LUA_NUMBER is the floating-point type used by Lua.
419@@ LUAI_UACNUMBER is the result of an 'usual argument conversion' 419@@ LUAI_UACNUMBER is the result of a 'default argument promotion'
420@@ over a floating number. 420@@ over a floating number.
421@@ l_mathlim(x) corrects limit name 'x' to the proper float type 421@@ l_mathlim(x) corrects limit name 'x' to the proper float type
422** by prefixing it with one of FLT/DBL/LDBL. 422** by prefixing it with one of FLT/DBL/LDBL.
@@ -433,7 +433,8 @@
433 433
434#define l_floor(x) (l_mathop(floor)(x)) 434#define l_floor(x) (l_mathop(floor)(x))
435 435
436#define lua_number2str(s,sz,n) l_sprintf((s), sz, LUA_NUMBER_FMT, (n)) 436#define lua_number2str(s,sz,n) \
437 l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))
437 438
438/* 439/*
439@@ lua_numbertointeger converts a float number to an integer, or 440@@ lua_numbertointeger converts a float number to an integer, or
@@ -510,7 +511,7 @@
510** 511**
511@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER. 512@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
512** 513**
513@@ LUAI_UACINT is the result of an 'usual argument conversion' 514@@ LUAI_UACINT is the result of a 'default argument promotion'
514@@ over a lUA_INTEGER. 515@@ over a lUA_INTEGER.
515@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers. 516@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.
516@@ LUA_INTEGER_FMT is the format for writing integers. 517@@ LUA_INTEGER_FMT is the format for writing integers.
@@ -523,10 +524,12 @@
523/* The following definitions are good for most cases here */ 524/* The following definitions are good for most cases here */
524 525
525#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d" 526#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d"
526#define lua_integer2str(s,sz,n) l_sprintf((s), sz, LUA_INTEGER_FMT, (n))
527 527
528#define LUAI_UACINT LUA_INTEGER 528#define LUAI_UACINT LUA_INTEGER
529 529
530#define lua_integer2str(s,sz,n) \
531 l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))
532
530/* 533/*
531** use LUAI_UACINT here to avoid problems with promotions (which 534** use LUAI_UACINT here to avoid problems with promotions (which
532** can turn a comparison between unsigneds into a signed comparison) 535** can turn a comparison between unsigneds into a signed comparison)
@@ -624,7 +627,8 @@
624** provide its own implementation. 627** provide its own implementation.
625*/ 628*/
626#if !defined(LUA_USE_C89) 629#if !defined(LUA_USE_C89)
627#define lua_number2strx(L,b,sz,f,n) ((void)L, l_sprintf(b,sz,f,n)) 630#define lua_number2strx(L,b,sz,f,n) \
631 ((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))
628#endif 632#endif
629 633
630 634