# HG changeset patch # User jbe # Date 1406321412 -7200 # Node ID ff39d4a310b984e598a5c26338b5f75c922d5fc4 # Parent 9ad1165cf3a14bb8efa994af59548ebd493267de Float parser for JSON library (non strict) diff -r 9ad1165cf3a1 -r ff39d4a310b9 libraries/json/json.c --- a/libraries/json/json.c Fri Jul 25 22:25:53 2014 +0200 +++ b/libraries/json/json.c Fri Jul 25 22:50:12 2014 +0200 @@ -1,5 +1,6 @@ #include #include +#include #include #define JSON_VALUE 0 @@ -145,7 +146,14 @@ luaL_pushresultsize(&luabuf, writepos); goto json_import_process_value; } - if (!strncmp(str+pos, "true", 4)) { + if (c == '-' || (c >= '0' && c <= '9')) { + char *endptr; + double numval; + numval = strtod(str+pos, &endptr); + if (endptr == str+pos) goto json_import_syntax_error; + pos += endptr - (str+pos); + lua_pushnumber(L, numval); + } else if (!strncmp(str+pos, "true", 4)) { lua_pushboolean(L, 1); pos += 4; } else if (!strncmp(str+pos, "false", 5)) {