Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: FriedEgg/json4lua
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: sheenhx/json4lua
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Jun 24, 2015

  1. disable all the error message

    sheenhx committed Jun 24, 2015
    Copy the full SHA
    8d38b73 View commit details
Showing with 21 additions and 22 deletions.
  1. +1 −1 README.md
  2. +20 −21 json/json.lua
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ JSON and JSONRPC for Lua modified by Sheen@relayr

Due to the packet loss in the wireless systems, we often have impaired json messages.

Now we modified all the error notifications to return json.null.
Now we modified all the error notifications to return nothing.

# Installation #
```
41 changes: 20 additions & 21 deletions json/json.lua
100755 → 100644
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ end
function json.decode(s, startPos)
startPos = startPos and startPos or 1
startPos = decode_scanWhitespace(s,startPos)
--assert(startPos<=string.len(s), 'Unterminated JSON encoded object found at position in [' .. s .. ']')
assert(startPos<=string.len(s), 'Unterminated JSON encoded object found at position in [' .. s .. ']')
local curChar = string.sub(s,startPos,startPos)
-- Object
if curChar=='{' then
@@ -163,20 +163,20 @@ end
function decode_scanArray(s,startPos)
local array = {} -- The return value
local stringLen = string.len(s)
--assert(string.sub(s,startPos,startPos)=='[','decode_scanArray called but array does not start at position ' .. startPos .. ' in string:\n'..s )
assert(string.sub(s,startPos,startPos)=='[','decode_scanArray called but array does not start at position ' .. startPos .. ' in string:\n'..s )
startPos = startPos + 1
-- Infinite loop for array elements
repeat
startPos = decode_scanWhitespace(s,startPos)
--assert(startPos<=stringLen,'JSON String ended unexpectedly scanning array.')
assert(startPos<=stringLen,'JSON String ended unexpectedly scanning array.')
local curChar = string.sub(s,startPos,startPos)
if (curChar==']') then
return array, startPos+1
end
if (curChar==',') then
startPos = decode_scanWhitespace(s,startPos+1)
end
--assert(startPos<=stringLen, 'JSON String ended unexpectedly scanning array.')
assert(startPos<=stringLen, 'JSON String ended unexpectedly scanning array.')
object, startPos = json.decode(s,startPos)
table.insert(array,object)
until false
@@ -187,9 +187,9 @@ end
-- @param string s The JSON string to scan.
-- @param int startPos The starting position of the comment
function decode_scanComment(s, startPos)
--assert( string.sub(s,startPos,startPos+1)=='/*', "decode_scanComment called but comment does not start at position " .. startPos)
assert( string.sub(s,startPos,startPos+1)=='/*', "decode_scanComment called but comment does not start at position " .. startPos)
local endPos = string.find(s,'*/',startPos+2)
--assert(endPos~=nil, "Unterminated comment in string at " .. startPos)
assert(endPos~=nil, "Unterminated comment in string at " .. startPos)
return endPos+2
end

@@ -230,7 +230,7 @@ function decode_scanNumber(s,startPos)
end
local stringValue = 'return ' .. string.sub(s,startPos, endPos-1)
local stringEval = loadstring(stringValue)
--assert(stringEval, 'Failed to scan number [ ' .. stringValue .. '] in JSON string at position ' .. startPos .. ' : ' .. endPos)
assert(stringEval, 'Failed to scan number [ ' .. stringValue .. '] in JSON string at position ' .. startPos .. ' : ' .. endPos)
return stringEval(), endPos
end

@@ -244,31 +244,30 @@ function decode_scanObject(s,startPos)
local object = {}
local stringLen = string.len(s)
local key, value
--assert(string.sub(s,startPos,startPos)=='{','decode_scanObject called but object does not start at position ' .. startPos .. ' in string:\n' .. s)
assert(string.sub(s,startPos,startPos)=='{','decode_scanObject called but object does not start at position ' .. startPos .. ' in string:\n' .. s)
startPos = startPos + 1
repeat
startPos = decode_scanWhitespace(s,startPos)
--assert(startPos<=stringLen, 'JSON string ended unexpectedly while scanning object.')
if startPos<=stringLen then
return 'null' --Modifed by Sheen, Jun 2015
end
local curChar = string.sub(s,startPos,startPos)
if (curChar=='}') then
return object,startPos+1
end
if (curChar==',') then
startPos = decode_scanWhitespace(s,startPos+1)
end
--assert(startPos<=stringLen, 'JSON string ended unexpectedly scanning object.')
assert(startPos<=stringLen, 'JSON string ended unexpectedly scanning object.')
-- Scan the key
key, startPos = json.decode(s,startPos)
--assert(startPos<=stringLen, 'JSON string ended unexpectedly searching for value of key ' .. key)
assert(startPos<=stringLen, 'JSON string ended unexpectedly searching for value of key ' .. key)
startPos = decode_scanWhitespace(s,startPos)
--assert(startPos<=stringLen, 'JSON string ended unexpectedly searching for value of key ' .. key)
--assert(string.sub(s,startPos,startPos)==':','JSON object key-value assignment mal-formed at ' .. startPos)
assert(startPos<=stringLen, 'JSON string ended unexpectedly searching for value of key ' .. key)
assert(string.sub(s,startPos,startPos)==':','JSON object key-value assignment mal-formed at ' .. startPos)
startPos = decode_scanWhitespace(s,startPos+1)
-- assert(startPos<=stringLen, 'JSON string ended unexpectedly searching for value of key ' .. key)
assert(startPos<=stringLen, 'JSON string ended unexpectedly searching for value of key ' .. key)
value, startPos = json.decode(s,startPos)
if key == nil then
return 'null'
end
object[key]=value
until false -- infinite loop while key-value pairs are found
end
@@ -298,11 +297,11 @@ end})
-- @param startPos The starting position of the scan.
-- @return string, int The extracted string as a Lua string, and the next character to parse.
function decode_scanString(s,startPos)
--assert(startPos, 'decode_scanString(..) called without start position')
assert(startPos, 'decode_scanString(..) called without start position')
local startChar = string.sub(s,startPos,startPos)
-- START SoniEx2
-- PS: I don't think single quotes are valid JSON
--assert(startChar == [["]] or startChar == [[']],'decode_scanString called for a non-string')
assert(startChar == [["]] or startChar == [[']],'decode_scanString called for a non-string')
--assert(startPos, "String decoding failed: missing closing " .. startChar .. " for string at position " .. oldStart)
local t = {}
local i,j = startPos,startPos
@@ -318,7 +317,7 @@ function decode_scanString(s,startPos)
local a = string.sub(s,j+1,j+4)
j = j + 4
local n = tonumber(a, 16)
--assert(n, "String decoding failed: bad Unicode escape " .. a .. " at position " .. i .. " : " .. j)
assert(n, "String decoding failed: bad Unicode escape " .. a .. " at position " .. i .. " : " .. j)
-- math.floor(x/2^y) == lazy right shift
-- a % 2^b == bitwise_and(a, (2^b)-1)
-- 64 = 2^6
@@ -339,7 +338,7 @@ function decode_scanString(s,startPos)
end
end
table.insert(t,string.sub(j, j+1))
--assert(string.find(s, startChar, j+1), "String decoding failed: missing closing " .. startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")")
assert(string.find(s, startChar, j+1), "String decoding failed: missing closing " .. startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")")
return table.concat(t,""), j+2
-- END SoniEx2
end