Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fpconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions fpconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*/
19 changes: 15 additions & 4 deletions lua_cjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this still be named "number", as the number type is generic, and may be 32 or 64 bit?
(i.e. it's called lua_pushnumber for that reason)

lua_pushnumber(l, token->value.number);
break;;
case T_BOOLEAN:
Expand Down