mirror of https://github.com/rusefi/lua.git
more consistent use of locale radix character across Lua
This commit is contained in:
parent
6ffe006f5c
commit
48d0674c2e
13
liolib.c
13
liolib.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: liolib.c,v 2.142 2015/01/02 12:50:28 roberto Exp roberto $
|
||||
** $Id: liolib.c,v 2.143 2015/03/06 19:09:08 roberto Exp roberto $
|
||||
** Standard I/O (and system) library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -410,12 +410,6 @@ static int readdigits (RN *rn, int hex) {
|
|||
}
|
||||
|
||||
|
||||
/* access to locale "radix character" (decimal point) */
|
||||
#if !defined(l_getlocaledecpoint)
|
||||
#define l_getlocaledecpoint() (localeconv()->decimal_point[0])
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Read a number: first reads a valid prefix of a numeral into a buffer.
|
||||
** Then it calls 'lua_stringtonumber' to check whether the format is
|
||||
|
@ -425,9 +419,10 @@ static int read_number (lua_State *L, FILE *f) {
|
|||
RN rn;
|
||||
int count = 0;
|
||||
int hex = 0;
|
||||
char decp[2] = ".";
|
||||
char decp[2];
|
||||
rn.f = f; rn.n = 0;
|
||||
decp[0] = l_getlocaledecpoint(); /* get decimal point from locale */
|
||||
decp[0] = lua_getlocaledecpoint(); /* get decimal point from locale */
|
||||
decp[1] = '\0';
|
||||
l_lockfile(rn.f);
|
||||
do { rn.c = l_getc(rn.f); } while (isspace(rn.c)); /* skip spaces */
|
||||
test2(&rn, "-+"); /* optional signal */
|
||||
|
|
9
llex.c
9
llex.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: llex.c,v 2.90 2015/03/03 18:17:04 roberto Exp roberto $
|
||||
** $Id: llex.c,v 2.91 2015/03/28 19:14:47 roberto Exp roberto $
|
||||
** Lexical Analyzer
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -221,11 +221,6 @@ static void buffreplace (LexState *ls, char from, char to) {
|
|||
}
|
||||
|
||||
|
||||
#if !defined(l_getlocaledecpoint)
|
||||
#define l_getlocaledecpoint() (localeconv()->decimal_point[0])
|
||||
#endif
|
||||
|
||||
|
||||
#define buff2num(b,o) (luaO_str2num(luaZ_buffer(b), o) != 0)
|
||||
|
||||
/*
|
||||
|
@ -234,7 +229,7 @@ static void buffreplace (LexState *ls, char from, char to) {
|
|||
*/
|
||||
static void trydecpoint (LexState *ls, TValue *o) {
|
||||
char old = ls->decpoint;
|
||||
ls->decpoint = l_getlocaledecpoint();
|
||||
ls->decpoint = lua_getlocaledecpoint();
|
||||
buffreplace(ls, old, ls->decpoint); /* try new decimal separator */
|
||||
if (!buff2num(ls->buff, o)) {
|
||||
/* format error with correct decimal point: no more options */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lstrlib.c,v 1.226 2015/02/09 18:05:46 roberto Exp roberto $
|
||||
** $Id: lstrlib.c,v 1.227 2015/03/28 19:14:47 roberto Exp roberto $
|
||||
** Standard library for string operations and pattern-matching
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -803,6 +803,7 @@ static int str_gsub (lua_State *L) {
|
|||
** Hexadecimal floating-point formatter
|
||||
*/
|
||||
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
|
||||
#define SIZELENMOD (sizeof(LUA_NUMBER_FRMLEN)/sizeof(char))
|
||||
|
@ -850,7 +851,7 @@ static int num2straux (char *buff, lua_Number x) {
|
|||
m = adddigit(buff, n++, m * (1 << L_NBFD)); /* add first digit */
|
||||
e -= L_NBFD; /* this digit goes before the radix point */
|
||||
if (m > 0) { /* more digits? */
|
||||
buff[n++] = '.'; /* add radix point */
|
||||
buff[n++] = lua_getlocaledecpoint(); /* add radix point */
|
||||
do { /* add as many digits as needed */
|
||||
m = adddigit(buff, n++, m * 16);
|
||||
} while (m > 0);
|
||||
|
|
14
luaconf.h
14
luaconf.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: luaconf.h,v 1.248 2015/03/06 19:49:50 roberto Exp roberto $
|
||||
** $Id: luaconf.h,v 1.249 2015/03/31 12:00:07 roberto Exp roberto $
|
||||
** Configuration file for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -569,7 +569,7 @@
|
|||
|
||||
/*
|
||||
** {==================================================================
|
||||
** Dependencies with C99
|
||||
** Dependencies with C99 and other C details
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
|
@ -626,6 +626,16 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@@ lua_getlocaledecpoint gets the locale "radix character" (decimal point).
|
||||
** Change that if you do not want to use C locales. (Code using this
|
||||
** macro must include header 'locale.h'.)
|
||||
*/
|
||||
#if !defined(lua_getlocaledecpoint)
|
||||
#define lua_getlocaledecpoint() (localeconv()->decimal_point[0])
|
||||
#endif
|
||||
|
||||
/* }================================================================== */
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue