webmcp

changeset 122:ff39d4a310b9

Float parser for JSON library (non strict)
author jbe
date Fri Jul 25 22:50:12 2014 +0200 (2014-07-25)
parents 9ad1165cf3a1
children 402fce94f98c
files libraries/json/json.c
line diff
     1.1 --- a/libraries/json/json.c	Fri Jul 25 22:25:53 2014 +0200
     1.2 +++ b/libraries/json/json.c	Fri Jul 25 22:50:12 2014 +0200
     1.3 @@ -1,5 +1,6 @@
     1.4  #include <lua.h>
     1.5  #include <lauxlib.h>
     1.6 +#include <stdlib.h>
     1.7  #include <string.h>
     1.8  
     1.9  #define JSON_VALUE 0
    1.10 @@ -145,7 +146,14 @@
    1.11      luaL_pushresultsize(&luabuf, writepos);
    1.12      goto json_import_process_value;
    1.13    }
    1.14 -  if (!strncmp(str+pos, "true", 4)) {
    1.15 +  if (c == '-' || (c >= '0' && c <= '9')) {
    1.16 +    char *endptr;
    1.17 +    double numval;
    1.18 +    numval = strtod(str+pos, &endptr);
    1.19 +    if (endptr == str+pos) goto json_import_syntax_error;
    1.20 +    pos += endptr - (str+pos);
    1.21 +    lua_pushnumber(L, numval);
    1.22 +  } else if (!strncmp(str+pos, "true", 4)) {
    1.23      lua_pushboolean(L, 1);
    1.24      pos += 4;
    1.25    } else if (!strncmp(str+pos, "false", 5)) {

Impressum / About Us