diff --git a/fpconv.c b/fpconv.c index 0e21748..91eab7d 100644 --- a/fpconv.c +++ b/fpconv.c @@ -40,7 +40,7 @@ * * This avoids the need for per thread storage or expensive checks * for call. */ -static char locale_decimal_point = '.'; +char locale_decimal_point = '.'; /* In theory multibyte decimal_points are possible, but * Lua CJSON only supports UTF-8 and known locales only have diff --git a/fpconv.h b/fpconv.h index 7b0d0ee..5ceeea5 100644 --- a/fpconv.h +++ b/fpconv.h @@ -17,6 +17,7 @@ extern void fpconv_init(); extern int fpconv_g_fmt(char*, double, int); extern double fpconv_strtod(const char*, char**); +extern char locale_decimal_point; /* vi:ai et sw=4 ts=4: */ diff --git a/lua_cjson.c b/lua_cjson.c index 3d1123e..0777835 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -86,7 +86,8 @@ typedef enum { T_ARR_BEGIN, T_ARR_END, T_STRING, - T_NUMBER, + T_INTEGER, + T_DOUBLE, T_BOOLEAN, T_NULL, T_COLON, @@ -103,7 +104,8 @@ static const char *json_token_type_name[] = { "T_ARR_BEGIN", "T_ARR_END", "T_STRING", - "T_NUMBER", + "T_INTEGER", + "T_DOUBLE", "T_BOOLEAN", "T_NULL", "T_COLON", @@ -1009,8 +1011,14 @@ static void json_next_number_token(json_parse_t *json, json_token_t *token) { char *endptr; - token->type = T_NUMBER; + token->type = T_INTEGER; token->value.number = fpconv_strtod(json->ptr, &endptr); + for(const char *i = json->ptr; i < endptr; i++){ + if(*i == locale_decimal_point){ + token->type = T_DOUBLE; + break; + } + } if (json->ptr == endptr) json_set_token_error(token, json, "invalid number"); else @@ -1240,7 +1248,10 @@ static void json_process_value(lua_State *l, json_parse_t *json, case T_STRING: lua_pushlstring(l, token->value.string, token->string_len); break;; - case T_NUMBER: + case T_INTEGER: + lua_pushinteger(l, token->value.number); + break;; + case T_DOUBLE: lua_pushnumber(l, token->value.number); break;; case T_BOOLEAN: