forked from Dependencies/lua-json
				
			Improved error message when encoding mixed/bad key types
							parent
							
								
									4fb28bbeee
								
							
						
					
					
						commit
						19b61e0628
					
				
							
								
								
									
										4
									
								
								json.lua
								
								
								
								
							
							
						
						
									
										4
									
								
								json.lua
								
								
								
								
							| 
						 | 
					@ -55,7 +55,7 @@ local function encode_table(val, stack)
 | 
				
			||||||
    local n = 0
 | 
					    local n = 0
 | 
				
			||||||
    for k in pairs(val) do
 | 
					    for k in pairs(val) do
 | 
				
			||||||
      if type(k) ~= "number" then
 | 
					      if type(k) ~= "number" then
 | 
				
			||||||
        error("invalid table: mixed key types")
 | 
					        error("invalid table: mixed or invalid key types")
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
      n = n + 1
 | 
					      n = n + 1
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
| 
						 | 
					@ -73,7 +73,7 @@ local function encode_table(val, stack)
 | 
				
			||||||
    -- Treat as an object
 | 
					    -- Treat as an object
 | 
				
			||||||
    for k, v in pairs(val) do
 | 
					    for k, v in pairs(val) do
 | 
				
			||||||
      if type(k) ~= "string" then
 | 
					      if type(k) ~= "string" then
 | 
				
			||||||
        error("invalid table: mixed key types")
 | 
					        error("invalid table: mixed or invalid key types")
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
      table.insert(res, encode(k, stack) .. ":" .. encode(v, stack))
 | 
					      table.insert(res, encode(k, stack) .. ":" .. encode(v, stack))
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue