webmcp

changeset 490:b29e082cafb8

Support for non-integer numbers in mondelefant_atom_connector (requires Lua 5.3)
author jbe
date Sun Jun 18 03:03:48 2017 +0200 (2017-06-18)
parents 42ddff7319e0
children 7a7770297ae8
files libraries/mondelefant/mondelefant_atom_connector.lua
line diff
     1.1 --- a/libraries/mondelefant/mondelefant_atom_connector.lua	Sun Jun 18 01:58:25 2017 +0200
     1.2 +++ b/libraries/mondelefant/mondelefant_atom_connector.lua	Sun Jun 18 03:03:48 2017 +0200
     1.3 @@ -43,17 +43,29 @@
     1.4  end
     1.5  
     1.6  input_converters["number"] = function(conn, value)
     1.7 -  local integer_string = string.format("%i", value)
     1.8 -  if tonumber(integer_string) == value then
     1.9 -    return integer_string
    1.10 -  else
    1.11 -    local number_string = tostring(value)
    1.12 -    if string.find(number_string, "^[0-9.e+-]+$") then
    1.13 -      return number_string
    1.14 +  if _VERSION == "Lua 5.2" then
    1.15 +    -- TODO: remove following compatibility hack to allow large integers (e.g. 1e14) in Lua 5.2
    1.16 +    local integer_string = string.format("%i", value)
    1.17 +    if tonumber(integer_string) == value then
    1.18 +      return integer_string
    1.19      else
    1.20 -      return "'NaN'"
    1.21 +      local number_string = tostring(value)
    1.22 +      if string.find(number_string, "^[0-9.e+-]+$") then
    1.23 +        return number_string
    1.24 +      else
    1.25 +        return "'NaN'"
    1.26 +      end
    1.27      end
    1.28    end
    1.29 +  local integer = math.tointeger(value)
    1.30 +  if integer then
    1.31 +    return tostring(integer)
    1.32 +  end
    1.33 +  local str = tostring(value)
    1.34 +  if string.find(str, "^[0-9.e+-]+$") then
    1.35 +    return str
    1.36 +  end
    1.37 +  return "'NaN'"
    1.38  end
    1.39  
    1.40  input_converters[atom.fraction] = function(conn, value)

Impressum / About Us