pax_global_header00006660000000000000000000000064125641760170014523gustar00rootroot0000000000000052 comment=04f93b0aa736bc9ea4845364311ef5b0da14fe58 lua-json-1.3.3/000077500000000000000000000000001256417601700132575ustar00rootroot00000000000000lua-json-1.3.3/LICENSE000066400000000000000000000025051256417601700142660ustar00rootroot00000000000000The following license is applied to all documents in this project with the exception of the 'tests' directory at the root. The 'tests' directory is dual-licenses Public Domain / MIT, whichever is least restrictive in your legal jurisdiction. The MIT License Copyright (c) 2008-2014 Thomas Harning Jr. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. lua-json-1.3.3/Makefile000066400000000000000000000024451256417601700147240ustar00rootroot00000000000000# # Makefile to prepare releases and run tests # DISTOPS= dist distclean dist-all dist-bzip2 dist-gzip dist-tar dist-zip .PHONY: all clean check $(DISTOPS) distcheck install LUA_BIN=lua LUNIT_BIN=lunit VERSION=luajson-$(shell git describe --abbrev=4 HEAD 2>/dev/null) MKDIR=mkdir -p PREFIX ?= /usr/local INSTALL_TOP= $(PREFIX) INSTALL_LMOD= $(INSTALL_TOP)/share/lua/5.1 INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/5.1 all: @echo Building nothing - no binaries clean: @echo Cleaning nothing - no binaries $(DISTOPS): $(MAKE) $(MFLAGS) -C dist $@ # Config to make sure that Lua uses the contained Lua code LUA_PATH_SETUP=LUA_PATH="?/init.lua;../lua/?.lua;../lua/?/init.lua;$(LUA_PATH);" LUA_SETUP=LUA_OLD_INIT="$(LUA_INIT)" LUA_INIT="@hook_require.lua" $(LUA_PATH_SETUP) check-regression: cd tests && $(LUA_SETUP) $(LUA_BIN) regressionTest.lua check-unit: cd tests && $(LUA_SETUP) $(LUNIT_BIN) lunit-*.lua check: check-regression check-unit distcheck-tar: dist-tar $(MKDIR) tmp tar -C tmp -xf dist/$(VERSION).tar cd tmp/$(VERSION) && make check rm -rf tmp distcheck-zip: dist-zip $(MKDIR) tmp unzip -q -d tmp dist/$(VERSION).zip cd tmp/$(VERSION) && make check rm -rf tmp distcheck: distcheck-zip distcheck-tar install: $(MKDIR) $(DESTDIR)$(INSTALL_LMOD) cp -p -r lua/* $(DESTDIR)$(INSTALL_LMOD) lua-json-1.3.3/README000066400000000000000000000042311256417601700141370ustar00rootroot00000000000000LuaJSON JSON Parser/Constructor for Lua Author: Thomas Harning Jr. Source code: http://repo.or.cz/luajson Bug reports: http://github.com/harningt/luajson harningt@gmail.com Requirements Lua 5.1, 5.2, or LuaJIT 2.0 LPeg (Tested with 0.7, 0.8, 0.9, 0.10, 0.12rc2 ... 0.6 mostly works) For regressionTest: lfs (Tested with 1.4.1) For lunit-tests: lunit >= 0.4 NOTE: LPeg 0.11 may not work - it crashed during my tests Lua versions tested recently: Lua 5.1.4 + strict + pl.strict Lua 5.2.0 + pl.strict LuaJIT-2.0.0-beta10 + strict + pl.strict License All-but tests: MIT-style, See LICENSE for details tests/*: Public Domain / MIT - whichever is least restrictive Module/Function overview: json.encode (callable module referencing json.encode.encode) --encode ( value : ANY-valid ) Takes in a JSON-encodable value and returns the JSON-encoded text Valid input types: table array-like table (spec below) string number boolean 'null' - represented by json.util.null Table keys (string,number,boolean) are encoded as strings, others are erroneus Table values are any valid input-type Array-like tables are converted into JSON arrays... Position 1 maps to JSON Array position 0 --isEncodable ( value : ANY ) Returns a boolean stating whether is is encodeable or not NOTE: Tables/arrays are not deeply inspected json.decode (callable module referencing json.decode.decode) --decode (data : string, strict : optional boolean) Takes in a string of JSON data and converts it into a Lua object If 'strict' is set, then the strict JSON rule-set is used json.util --printValue (tab : ANY, name : string) recursively prints out all object values - if duplicates found, reference printed --null Reference value to represent 'null' in a well-defined way to allow for null values to be inserted into an array/table --merge (t : table, ... : tables) Shallow-merges a sequence of tables onto table t by iterating over each using pairs and assigning. Attribution: parsing test suite from JSON_checker project of http://www.json.org/ No listed license for these files in their package. lua-json-1.3.3/ReleaseNotes.txt000077700000000000000000000000001256417601700231262docs/ReleaseNotes-1.3.3.txtustar00rootroot00000000000000lua-json-1.3.3/dist/000077500000000000000000000000001256417601700142225ustar00rootroot00000000000000lua-json-1.3.3/dist/Makefile000066400000000000000000000015611256417601700156650ustar00rootroot00000000000000VERSION= luajson-$(shell git describe --abbrev=4 HEAD 2>/dev/null) DIST_TAR= $(VERSION).tar DIST_BZ2= $(DIST_TAR).bz2 DIST_GZ= $(DIST_TAR).gz DIST_ZIP= $(VERSION).zip .PHONY: all clean dist distclean dist-bzip2 dist-gzip dist-tar dist-zip .DELETE_ON_ERROR: all: dist-all clean: dist-clean @echo Cleaning nothing - no binaries all dist dist-all: dist-tar dist-bzip2 dist-gzip dist-zip distclean: rm -f luajson-*.bz2 rm -f luajson-*.gz rm -f luajson-*.tar rm -f luajson-*.zip dist-tar: $(DIST_TAR) dist-bzip2: $(DIST_BZ2) dist-gzip: $(DIST_GZ) dist-zip: $(DIST_ZIP) $(DIST_TAR): cd .. && git archive --format=tar --prefix=$(VERSION)/ HEAD . -o $(CURDIR)/$@ $(DIST_BZ2): $(DIST_TAR) bzip2 -9 -c -f $(DIST_TAR) > $@ $(DIST_GZ): $(DIST_TAR) gzip -9 -c -f $(DIST_TAR) > $@ $(DIST_ZIP): cd .. && git archive --format=zip --prefix=$(VERSION)/ HEAD: -o $(CURDIR)/$@ lua-json-1.3.3/docs/000077500000000000000000000000001256417601700142075ustar00rootroot00000000000000lua-json-1.3.3/docs/LuaJSON.txt000066400000000000000000000130631256417601700161660ustar00rootroot00000000000000LuaJSON(3) ========== :Author: Thomas Harning :Email: harningt@gmail.com :Date: 2009/04/29 NAME ---- luajson - JSON encoder/decoder for Lua SYNOPSIS -------- local json = require("json") json.decode("json-string" [, parameters]) json.decode.getDecoder(parameters) json.encode(lua_value [, parameters]) json.encode.getEncoder(parameters) DESCRIPTION ----------- json.decode("json-string" [, parameters]):: Obtains a JSON decoder using `getDecoder` with the parameters specified, then performs the decoding operation. json.encode(lua_value [, parameters]):: Obtains a JSON encoder using `getEncoder` with the parameters specified, then performs the encoding operation. json.decode.getDecoder(parameters):: Obtains a JSON decoder configured with the given parameters or defaults. json.encode.getEncoder(parameters):: Obtains a JSON encoder configured with the given parameters or defaults. json.encode.strict:: A default parameter specification containing 'strict' rules for encoding json.decode.strict:: A default parameter specification containing 'strict' rules for decoding === COMMON PARAMETERS initialObject : boolean:: Specifies if the outermost element be an array or object allowUndefined : boolean:: Specifies if 'undefined' is an allowed value null : any:: Placeholder object for null values undefined : any:: Placeholder for undefined values number.nan : boolean:: Specifies if NaN is an allowed value number.inf : boolean:: Specifies if +/-Infinity is an allowed value === ENCODER-SPECIFIC PARAMETERS preProcess : `function(object)`:: Called for every value to be encoded, optionally altering. If returns `nil` then no value change occurs. output : function:: Function that returns an encoder specification (TBD), if null default used that returns a string. array.isArray : `function(object)`:: If `true`/`false` returned, then the value is authoritatively an array or not strings.xEncode : boolean:: Specifies if binary values are to be encoded with \xNN rather than \uNNNN strings.encodeSet : string:: http://www.lua.org/manual/5.1/manual.html#5.4.1[gmatch-style] set of characters that need to be escaped (to be contained in `[]`) strings.encodeSetAppend : string:: Set of characters that need to be escaped (to be contained in `[]`). Appended to the current encodeSet. ==== Default Configuration [source,lua] ---- array.isArray == json-util's isArray implementation allowUndefined = true number.nan = true number.inf = true strings.xEncode = false strings.encodeSet = '\\"/%z\1-\031' ---- ==== Strict Configuration [source,lua] ---- initialObject = true allowUndefined = false number.nan = false number.inf = false ---- === DECODER-SPECIFIC PARAMETERS unicodeWhitespace : boolean:: Specifies if unicode whitespace characters are counted array.trailingComma / object.trailingComma : boolean:: Specifies if extraneous trailing commas are ignored in declaration calls.defs : map:: Defines set of specifically permitted function definitions. If boolean value, determines if allowed or not, decoded as a call object. Function return-value is the decoded result. Function definition: `function(name, [arguments])` : output-value calls.allowUndefined : boolean:: Specifies if undefined call definitions are decoded as call objects. number.frac : boolean:: Specifies if numbers can have a decimal component (ex: `.01`) number.exp : boolean:: Specifies if exponents are allowed (ex: `1e2`) number.hex : boolean:: Specifies if hexadecimal numbers are allowed (ex: `0xDEADBEEF`) object.number : boolean:: Specifies if numbers can be object keys object.identifier : boolean:: Specifies if unquoted 'identifiers' can be object keys (matching `[A-Za-z_][A-Za-z0-9_]*`) strings.badChars : string:: Set of characters that should not be present in a string strings.additionalEscapes : LPeg expression:: LPeg expression to handle output (ex: `lpeg.C(1)` would take `\k` and spit out `k`) strings.escapeCheck : non-consuming LPeg expression:: LPeg expression to check if a given character is allowed to be an escape value strings.decodeUnicode:: `function (XX, YY)` handling \uXXYY situation to output decoded unicode sequence strings.strict_quotes : boolean:: Specifies if the `'` character is considered a quoting specifier ==== Default configuration [source,lua] ---- unicodeWhitespace = true initialObject = false allowUndefined = true array.trailingComma = true number.frac = true number.exp = true number.hex = false object.number = true object.identifier = true object.trailingComma = true strings.badChars = '' -- No characters considered bad in a string strings.additionalEscapes = false, -- disallow untranslated escapes strings.escapeCheck = #lpeg.S('bfnrtv/\\"xu\'z'), strings.decodeUnicode = utf8DecodeUnicode, strings.strict_quotes = false ---- ==== Strict configuration [source,lua] ---- initialObject = true allowUndefined = false array.trailingComma = false object.identifier = false object.trailingComma = false strings.badChars = '\b\f\n\r\t\v' strings.additionalEscapes = false -- no additional escapes strings.escapeCheck = #lpeg.S('bfnrtv/\\"u') --only these are allowed to be escaped strings.strict_quotes = true ---- AUTHOR ------ Written by Thomas Harning Jr., REFERENCES ---------- http://www.inf.puc-rio.br/~roberto/lpeg[LPeg] http://json.org[JSON] COPYING ------- Copyright (C) 2008-2009 Thomas Harning Jr. Free use of this software is granted under the terms of the MIT license. lua-json-1.3.3/docs/ReleaseNotes-0.10.txt000066400000000000000000000103041256417601700177130ustar00rootroot00000000000000luajson v0.10 Release Notes =========================== User Visible Changes -------------------- This release changes the system quite a bit from previous versions in that there is more configurability. There still is quite a bit of strong defaulting to make it accept more data formats and encode such that the most strict decoder *should* decode it. It is now possible to obtain wrapped-up encoders and decoders with options "compiled" in. With decoders this is particularly bound-up (LPEG patterns), encoders take advantage of this with less closure-count. Extended features of newer LPEG versions can also be used as they are available, either via function detection or version # parsing. New decoder features: * Single-quoted strings * Function-call decoding * Generic string management * String post-processing option * UTF-16 -> UTF-8 code decoding for "\uXXXX" from Emil Renner Berthing by default (not req) * Handle extended UTF-8 spacing characters and BOF for inter-element spacing New encoder features: * Function-call encoding * String pre-processing option * Fully modular encoding system * Encoding with similar option system as decoding Plans for next release ---------------------- 0.11 * UTF-8 encoding/decoding validation (currently decoding only supported) * Optional \xXX encoding * JSON encoding with fully 'strict' options * Generic output mechanism (ropes, IO, etc) 1.0 beta * Full API documentation * Stable encoder/decoder option-apis. Final 1.0 release will maintain that all options used in code will be future-proof, at least until 2.0 Updates since 0.9.1 =================== Emil Renner Berthing (1): decoder: Added proper utf8 decoding of strings Thomas Harning Jr (38): -ungrouped- Merge branch '0.9-rockspec' base: Setup 0.9.1 rockspec with md5 of luaforge release added luarocks module to check out luajson from git (requires git patch) Preparing for next release pre-emptively decode-util: during a table merge, if a nil is located, skip it decoder/test: Added preliminary function-call handling Require name is string and func is function Support both patterns and strings as function name specifiers function calls receive as first argument the name used added support for multiple arguments to functions Moved function-call decoder to separate module added string post-processing utility decoder/tests: adds support for single-quoted strings w/ expected escape-handling support unicode whitespaces as whitespace around values decoder: Fully modularized strings/number/calls data-types Refactored boolean/null/undefined out into the 'others' module Provide workaround for missing lpeg.type in lpeg 0.6, 0.7, ... More stabilization of string decoder configuration as well as hooking unicode-handling in optimized 'number' option-defaulting unified configuration system into a fast-cached Tokend which only permits card-readng ops (writing in seprate referece...) Fixed return assertion to prevent 'Invalid JSON data' from being returned as second result Added simple LPEG version parser "x.y.z.." => x.y Added support for LPEG 0.9 accumulator replacement (fold) which may be faster string.char => string_char for optimization in utf8 decoder encoder/decoder: added support for 'undefined' value encoder/test: exposed and test string preprocessing option encoder: add string preprocessor handler (for encoding->utf8 mgmt) Break apart the encoder into distinct modules + add call encoding split out number encoder into own file to mirror decoder added applicable configuration options from the decoder to the number encoder enhanced configuration support to match the decoder's optionset where appropriate added 'initialObject' check to assert that the root object is in fact an object/array mirrored decoder's getDecoder => getEncoder setup performed full modularization of the encoder + added function-encode tests tests: Removed package.path alteration since 'make check' handles that as well as luarocks applied configuration optimizations take advantage of the encoder optimizations and simplifications from the decoders added UTF-16 => UTF-8 encoder test extends UTF tests with boundary tests and test # for break detect lua-json-1.3.3/docs/ReleaseNotes-0.9.1.txt000066400000000000000000000007571256417601700200150ustar00rootroot00000000000000luajson v0.9.1 Release Notes ============================ User Visible Changes -------------------- LuaRocks package created. Plans for next release ---------------------- * Make the encoder customizable in a manner similar to the decoder * Try to create an integration point for unicode handling * Add in custom 'function' handling for decoder (ex: b64(stringvalue)) Updates since 0.9 ================= Thomas Harning Jr (1): base: Preparation to make luajson work as a luarocks rock lua-json-1.3.3/docs/ReleaseNotes-0.9.txt000066400000000000000000000034051256417601700176470ustar00rootroot00000000000000luajson v0.9 Release Notes ========================== User Visible Changes -------------------- There are more tests added in using the lunit framework. These are particularly useful for testing and debugging small components in the luajson decoder/encoder sections. Decoders are now customizable in a modular manner. For example: You can construct a decoder that allows for NaN and Inf values, but be strict on everything else. The support framework should permit for more enhancements and custom elements. Plans for next release ---------------------- * Make the encoder customizable in a manner similar to the decoder * Try to create an integration point for unicode handling * Add in custom 'function' handling for decoder (ex: b64(stringvalue)) * Create luarocks Updates since 0.6 ================= Thomas Harning Jr (15): base: Added changelog (with details for 0.6) Noted lunit 0.4 requirement Make distcheck properly run the check inside the dist decoder/encoder: Added support for primitive Array metatable marker to mark arrays as such decoder/test: Added hex decode capability decoder: Cleaned up unused values in the base decoder Refactored decoding mechanism to permit building even more customized decoders Fixed decoder generation to return cached versions fixed decoder to remove misnamed parameters (causing failed tests) Allow negative inf test: Reconfigured the tests to behave more correctly and allow for a simpler addition mechanism. Enhanced the regression tests to handle roundtripping in a sane manner Updated regression tests for roundtripping to have a better output format and handle outer whitespace and moved tests Added lunit-based tests for fine-grained tests Made lunit tests use 'setup' to simplify decoder hooking lua-json-1.3.3/docs/ReleaseNotes-1.0.1.txt000066400000000000000000000022141256417601700177730ustar00rootroot00000000000000luajson v1.0.1 Release Notes ============================ User Visible Changes -------------------- Duplicate references are allowed if it does not cause circular references. This allows something like the following to be valid, where it was not before: a = {1, 2, 3} json.encode({a, a}) Decoding this will not be handled in any special way, it will be encoded as: [ [1,2,3], [1,2,3] ] Plans for next release ---------------------- The 1.1 release will contain support for arbitrary configurations in the same manner as the built-in configurations. It will also contain support for a simple decoder where `null` and `undefined` values are mapped to nil, rather than the more complicated round-trip capable constants. Updates since 1.0 ================= Thomas Harning Jr (3): base: updates utility to help construct lua rocks to provide stable output encoder: adds support for non-circular duplicate object references tests: adds encoding test for circular/non-circular duplicate values Contributions ============= Thanks to Marcus Irven for reporting the issue with duplicate objects that aren't circular. lua-json-1.3.3/docs/ReleaseNotes-1.0.2.txt000066400000000000000000000022521256417601700177760ustar00rootroot00000000000000luajson v1.0.2 Release Notes ============================ User Visible Changes -------------------- In Windows, Lua's tostring and tonumber handling occur differently for the boundary cases of NaN, Infinity, and -Infinity values. This broke Windows encoding/decoding of JSON for which these values are present. Example input/outputs: Windows: * tonumber("Infinity") == nil * tostring(1/0) == "1.#INF" * tostring(0/0) == "-1.#IND" Linux: * tonumber("Infinity") == inf * tostring(1/0) == "inf" * tostring(0/0) == "nan" The code that decoded was changed to report the output manually on decode rather than decode 'generically' using 'tonumber'. The code that encoded was changed to use numerical equivalence checking before returning what 'tostring' would have, which should catch nearly all cases. Checks were updated to do: * nan => value ~= value * inf => value == math.huge * -inf => value == -math.huge Plans for next release ---------------------- Bugfixes only in the 1.0.x series. Updates since 1.0.1 =================== Thomas Harning Jr (2): decoder/encoder: better handles number encoding/decoding for cases where tonumber/tostring don't work as expected lua-json-1.3.3/docs/ReleaseNotes-1.0.3.txt000066400000000000000000000010571256417601700200010ustar00rootroot00000000000000luajson v1.0.3 Release Notes ============================ User Visible Changes -------------------- LPeg 0.10 now supported. The only problem was the mechanism for version detection. I now use object detection which should better work for future version updates. Plans for next release ---------------------- See 1.2.x series for future plans. Updates since 1.0.2 =================== Thomas Harning Jr (2): decode/object: compatibility fix for LPeg 0.10 - function-checking vs number parsing docs: adds reference for where bug reporting should go lua-json-1.3.3/docs/ReleaseNotes-1.0.txt000066400000000000000000000075451256417601700176500ustar00rootroot00000000000000luajson v1.0 Release Notes ========================== User Visible Changes -------------------- This release marks the 1.0 release that has been in the works for quite some time. One of the major release items is detailed documentation and a reasonably stable/ clean API. Some features have been eliminated since they were not effective or used. Features removed: * Lax number handling... before this release, numbers with ugly definition were permitted, such as leading zeroes, multiple negative signs, ... * String post-processing... this feature was unused and appears to serve no useful purpose. Removing it made unifying encoding/decoding options simpler * Adds global pre-processing to handle arbitrary conversion of values during encoding. Changes: * String escape codes updated to match what the JSON spec uses for encoding Additions: * Add optional \x00 character encoding to handle encoding single bytes * Custom output stream functionality to create optimal output mechanisms that can stream JSON output. Plans for next release ---------------------- Currently there is nothing in the works for the next release. The project is very open to outside suggestions and patches for enhanced functionality... so please contribute. Updates since 0.10 ================== Thomas Harning Jr (46): -ungrouped- Rockspec 0.10 moved lua sources into 'lua' to assist luarocks management base: makefiles learn high bzip2 and gzip compression adds new rockspec for github updated github rockspec to reference all of the files Makefile learns split-apart checking rockspec 0.10-2 update -- previous one had improper luaforge link decoder/strings: removed unused 'postProcess' option removed unused 'null' decoder remove catchall escape handler from default applied minor cleanups added error analysis for strings + generic bad-character utility decoder/tests: remove depth limiting support code, implementation, and tests implemented non-defined call captures and updated tests to handle cases removed lax number handling (leading zeroes, multiple negatives, and spaces between - and digits) fixes ambiguous/invalid hex numbers with decimal/scientific format decoder: reorders replacements based on spec, adds 'x' escape allow whitespace before strict object/array generalizes decoding using grammar entries docs: preliminary documentation of options created markdown documentation to be translated into manpage-style documentation moves documentation to asciidoc encoder/decoder/tests: moves json.decode.util.merge => json.util.merge call-generation/handling moved to json.util and unified removes discrimination between calls with 1 and * arguments encoder/decoder: applied license headers to files missing them encoder/tests: move preprocessing to root to permit global pre-processor (ex: take special strings and base64-encode to call) encoder: add vertical tabulation character to the encoded set adds \xXX encoding and customizable encoding set adds custom output-encoder support while keeping default case optimal using templates adds output-stream writer for encoding consulted JSON specification and updated string definitions to match note encoding > 7F with escapes is hazardous properly capture expected range-of-characters to map updates strict encoding to use correct calls check and ordering correct language of disabled 'undefined' value cleans up code and errors removes extraneous 'defs' from the default options tests: adds \u and \x escape encoding/decoding test cases test strict form of string decoding tests updates strict string test to use strict encoder regression-test uses test strict encoder in strict tests adds strict encoder regression tests report error cause during regressionTest encoding failures added pre-value whitespace tests updated tests to match new stricter default syntax lua-json-1.3.3/docs/ReleaseNotes-1.1.1.txt000066400000000000000000000025341256417601700200010ustar00rootroot00000000000000 luajson v1.1.1 Release Notes ============================ User Visible Changes -------------------- In Windows, Lua's tostring and tonumber handling occur differently for the boundary cases of NaN, Infinity, and -Infinity values. This broke Windows encoding/decoding of JSON for which these values are present. Example input/outputs: Windows: * tonumber("Infinity") == nil * tostring(1/0) == "1.#INF" * tostring(0/0) == "-1.#IND" Linux: * tonumber("Infinity") == inf * tostring(1/0) == "inf" * tostring(0/0) == "nan" The code that decoded was changed to report the output manually on decode rather than decode 'generically' using 'tonumber'. The code that encoded was changed to use numerical equivalence checking before returning what 'tostring' would have, which should catch nearly all cases. Checks were updated to do: * nan => value ~= value * inf => value == math.huge * -inf => value == -math.huge Plans for next release ---------------------- The next version should hopefully have more error reporting capabilities, such as returning where an error occurred and possibly details. How this will be done is a research-item. Updates since 1.1 ================= Thomas Harning Jr (3): -ungrouped- Merge branch '1.0.x' decoder/encoder: better handles number encoding/decoding for cases where tonumber/tostring don't work as expected lua-json-1.3.3/docs/ReleaseNotes-1.1.2.txt000066400000000000000000000010601256417601700177730ustar00rootroot00000000000000luajson v1.1.2 Release Notes ============================ User Visible Changes -------------------- LPeg 0.10 now supported. The only problem was the mechanism for version detection. I now use object detection which should better work for future version updates. Plans for next release ---------------------- See 1.2.x series for future plans. Updates since 1.1.1 =================== Thomas Harning Jr (4): decode/object: compatibility fix for LPeg 0.10 - function-checking vs number parsing docs: adds reference for where bug reporting should go lua-json-1.3.3/docs/ReleaseNotes-1.1.txt000066400000000000000000000017071256417601700176430ustar00rootroot00000000000000luajson v1.1 Release Notes ========================== User Visible Changes -------------------- A new default configuration "simple" is available that does not use `json.util.null` and `json.util.undefined` to represent their associated JSON values. There is also a change in the decoding of arrays with nulls to avoid special casing it. Plans for next release ---------------------- No plans yet for what a future release might contain. Updates since 1.0.1 =================== Thomas Harning Jr (9): -ungrouped- Merge branch '1.0.x' decoder: learns how to handle arbitrary sets of defaults (now + simple) adds support for nil return values fixes bug where function call returns nothing => error adds support for 'simple' decoding to map null and undefined => nil removes special casing of null values in an array adds support for caching new arbitrary configs tests: tests added for simple/default decoders stand-alone, in arrays, in objects lua-json-1.3.3/docs/ReleaseNotes-1.2.1.txt000066400000000000000000000016411256417601700200000ustar00rootroot00000000000000luajson v1.2.1 Release Notes ============================ User Visible Changes -------------------- LPeg 0.10 now supported. The only problem was the mechanism for version detection. I now use object detection which should better work for future version updates. Plans for next release ---------------------- No change in the plans for the next release. For the next feature release, I plan on better fleshing out the enhanced error handling and possibly adding in the more customizable output system. For previews of the features that might make it into the next release, please see the "next" branch. Note that this branch is volatile and features may vanish rather than be reverted for cleanliness. Enhanced error handling introduced in LPeg 0.10 might help this task. Updates since 1.2 ================= Thomas Harning Jr (6): decode/object: compatibility fix for LPeg 0.10 - function-checking vs number parsing lua-json-1.3.3/docs/ReleaseNotes-1.2.2.txt000066400000000000000000000026131256417601700200010ustar00rootroot00000000000000luajson v1.2.2 Release Notes ============================ User Visible Changes -------------------- Addressed issue #14, increasing the decoding max stack depth to ~190 using nested parsing. This should help deal with deeply-nested objects until a better solution is achieved. Addressed issue #15, the 'preProcess' function receives an additional parameter 'isObjectKey' to help it determine what sort of processing should be done. Adds a 'string' processor function that can be used to specially handle string values and custom escape values, such as for forcing ASCII by encoding all UTF-8 values using escape codes. Plans for next release ---------------------- Future enhancements in the 1.2 series include linearizing the parsing layer to make deep nesting less costly in terms of stack space. For the next series, better error handling is a goal. Updates since 1.2.1 =================== Thomas Harning Jr (16): base: splits out Makefile to multiple files to manage distinct goals and adds install target decoder: updates decoders for nested data types to use Cmt when available to handle deep nesting by directly matching inside encoder/strings: adds simple processor+tests - with example use case of encoding multi-byte utf8 values encoder/tests: communicates the status that a value is an object key to the preProcess function if present tests: adds decoder test for maximum depth of parser lua-json-1.3.3/docs/ReleaseNotes-1.2.txt000066400000000000000000000042221256417601700176370ustar00rootroot00000000000000luajson v1.2 Release Notes ========================== Tested LPeg versions: * 0.9 - pass * 0.8 - pass * 0.7 - pass * 0.6 - fail : cannot handle 'nil' returns -> tranforms into booleans Note that 0.6 passes strict mode tests and behaviors. It just breaks down when decoding the plain return value `null` or `undefined` that would result in a `nil` return value. User Visible Changes -------------------- setObjectKey ~~~~~~~~~~~~ Thanks to Alexander Gladysh, we now have the "setObjectKey" hook to permit more customizable behavior during object construction. There is a new 'object' option that you can set to handle custom key-value setting. If you set in the configuration table .object.setObjectKey to a function with the signature `(tab, key, value)`, you will override the `rawset` style behavior. Example: json.decode("{'1':true, x:true}") --> { ["1"] = true, x = true } function newSetObjectKey(tab, key, value) local numkey = tonumber(key) key = numkey or key rawset(tab, key, value) end json.decode("{'1':true, x:true}", { object = { setObjectKey = newSetObjectKey } }) --> { [1] = true, x = true } require builtins update ~~~~~~~~~~~~~~~~~~~~~~~ Also changed is the major change to `require` as many of the default packages as possible to better help custom embedding scenarios where 'default' tables such as `io` and `os` may require on-demand loading via `require`. Plans for next release ---------------------- For the next feature release, I plan on better fleshing out the enhanced error handling and possibly adding in the more customizable output system. For previews of the features that might make it into the next release, please see the "next" branch. Note that this branch is volatile and features may vanish rather than be reverted for cleanliness. Updates since 1.1.1 =================== Thomas Harning Jr (4): all: pulls in all but base/package modules via require (io,os,string,table,math) decoder: implements setObjectKey for LPeg < 0.9 Moves 'setObjectKey' from root of `options` to `options.object` docs: adds reference for where bug reporting should go Alexander Gladysh (1): decoder: configurable object key filter lua-json-1.3.3/docs/ReleaseNotes-1.3.1.txt000066400000000000000000000021161256417601700177770ustar00rootroot00000000000000luajson v1.3.1 Release Notes ============================ User Visible Changes -------------------- This release does not introduce many changes. François Perrad kindly produced patches to make it work better with Lua 5.2 and handle strict modes. It also introduces additional documentation about what varieties of Lua have been tested. Plans for next release ---------------------- A future release will have a stronger focus on decoder performance. It may mean a reduction in flexibility by removing options and breaking compatibility. Updates since 1.3 ================= François Perrad (7): -ungrouped- fix with Lua 5.2 strict remove the condition around `_ENV = nil` remove conditional (is_52) code fix tests fix test with Lua 5.2.0 lfs : fix with Lua 5.2 strict Thomas Harning Jr (7): -ungrouped- Merge pull request #21 from fperrad/compat51_52 Merge pull request #22 from fperrad/patch-1 Merge pull request #23 from fperrad/patch-2 all: adds module metadata as suggested by fperrad decoder: fixes 5.2-strict mode state object docs: notes tested Lua versions lua-json-1.3.3/docs/ReleaseNotes-1.3.2.txt000066400000000000000000000016511256417601700200030ustar00rootroot00000000000000luajson v1.3.2 Release Notes ============================ User Visible Changes -------------------- One of the main changes in this release is compatibility with LPeg 0.12 and more sane _ENV manipulation to avoid problems in strict environments. The documentation has also been updated to reflect the behavior of the often-used 'merge' utility to avoid surprises in behavior. Plans for next release ---------------------- A future release will have a stronger focus on decoder performance. It may mean a reduction in flexibility by removing options and breaking compatibility. Updates since 1.3.1 =================== Thomas Harning Jr (6): all: sets _ENV to nil using local _ENV = nil to avoid global writing decoder: fixes compatibility with lpeg 0.12 by closing off 0-length captures in loops docs: documents testing with the Penlight 'strict' module adds merge behavior documentation updates LPeg testing information lua-json-1.3.3/docs/ReleaseNotes-1.3.3.txt000066400000000000000000000017141256417601700200040ustar00rootroot00000000000000luajson v1.3.3 Release Notes ============================ User Visible Changes -------------------- The main changes for this release are: * Allow objects with metatables to declare themselves as an array by setting __is_luajson_array as true in the metatable. * Pass all unit tests in Lua 5.2 (lunit tests had an issue) Plans for next release ---------------------- As declared in v1.3.2, a future release will have a stronger focus on decoder performance. It may mean a reduction in flexibility by removing options and breaking compatibility... so this would likely be either v1.4 or v2.0 Updates since 1.3.2 =================== Thomas Harning Jr (16): all: adds module metadata as suggested by fperrad base: fixes link for luarocks download updates rock creation tool to include tag version encoder: if __is_luajson_array is set on a metatable, consider the value as an array tests: fixes lunit test to work with Lua 5.2 environment management lua-json-1.3.3/docs/ReleaseNotes-1.3.txt000066400000000000000000000027741256417601700176520ustar00rootroot00000000000000luajson v1.3 Release Notes ========================== User Visible Changes -------------------- A global 'nothrow' option was added to change the behavior of parsing to not throw, but return `nil, error`. Error messages were also enhanced for many cases to include better details as to why the parsing may have failed. Some examples follow: For `[1i]` unexpected character @ character: 3 0:3 [i] line: [1i For `{x:1` Unclosed elements present The parser was also unrolled so that LPeg was placed more into a lexer role rather than full-blown parser. This solves the problem of LPeg running into problems in my parser due to unclosed choices at a small performance cost. Plans for next release ---------------------- A future release will have a stronger focus on decoder performance. It may mean a reduction in flexibility by removing options and breaking compatibility. Updates since 1.2.2 =================== Thomas Harning Jr (9): all: 5.2 compatibility update option processing system to do more pre-configuration to better prepare for future changes base: rockspec scm-4 added due to file layout change fixes luajson-scm-4.rockspec decoder: adds global 'nothrow' option to protect call automatically error detection enhancements from next branch overhaul update to be iterative to avoid call-stack buildup w/ limits and horrible performance hit tests: adds null array roundtrip issue per gh-4 Francois Perrad (2): -ungrouped- fix loadstring when Lua 5.2 is strict fix test suite with Lua 5.2 lua-json-1.3.3/lua/000077500000000000000000000000001256417601700140405ustar00rootroot00000000000000lua-json-1.3.3/lua/json.lua000066400000000000000000000010031256417601700155060ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local decode = require("json.decode") local encode = require("json.encode") local util = require("json.util") local _G = _G local _ENV = nil local json = { _VERSION = "1.3.4", _DESCRIPTION = "LuaJSON : customizable JSON decoder/encoder", _COPYRIGHT = "Copyright (c) 2007-2014 Thomas Harning Jr. ", decode = decode, encode = encode, util = util } _G.json = json return json lua-json-1.3.3/lua/json/000077500000000000000000000000001256417601700150115ustar00rootroot00000000000000lua-json-1.3.3/lua/json/decode.lua000066400000000000000000000102131256417601700167340ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local lpeg = require("lpeg") local error = error local pcall = pcall local jsonutil = require("json.util") local merge = jsonutil.merge local util = require("json.decode.util") local decode_state = require("json.decode.state") local setmetatable, getmetatable = setmetatable, getmetatable local assert = assert local ipairs, pairs = ipairs, pairs local string_char = require("string").char local type = type local require = require local _ENV = nil local modulesToLoad = { "composite", "strings", "number", "others" } local loadedModules = { } local json_decode = {} json_decode.default = { unicodeWhitespace = true, initialObject = false, nothrow = false } local modes_defined = { "default", "strict", "simple" } json_decode.simple = {} json_decode.strict = { unicodeWhitespace = true, initialObject = true, nothrow = false } for _,name in ipairs(modulesToLoad) do local mod = require("json.decode." .. name) if mod.mergeOptions then for _, mode in pairs(modes_defined) do mod.mergeOptions(json_decode[mode], mode) end end loadedModules[#loadedModules + 1] = mod end -- Shift over default into defaultOptions to permit build optimization local defaultOptions = json_decode.default json_decode.default = nil local function generateDecoder(lexer, options) -- Marker to permit detection of final end local marker = {} local parser = lpeg.Ct((options.ignored * lexer)^0 * lpeg.Cc(marker)) * options.ignored * (lpeg.P(-1) + util.unexpected()) local decoder = function(data) local state = decode_state.create(options) local parsed = parser:match(data) assert(parsed, "Invalid JSON data") local i = 0 while true do i = i + 1 local item = parsed[i] if item == marker then break end if type(item) == 'function' and item ~= jsonutil.undefined and item ~= jsonutil.null then item(state) else state:set_value(item) end end if options.initialObject then assert(type(state.previous) == 'table', "Initial value not an object or array") end -- Make sure stack is empty assert(state.i == 0, "Unclosed elements present") return state.previous end if options.nothrow then return function(data) local status, rv = pcall(decoder, data) if status then return rv else return nil, rv end end end return decoder end local function buildDecoder(mode) mode = mode and merge({}, defaultOptions, mode) or defaultOptions for _, mod in ipairs(loadedModules) do if mod.mergeOptions then mod.mergeOptions(mode) end end local ignored = mode.unicodeWhitespace and util.unicode_ignored or util.ascii_ignored -- Store 'ignored' in the global options table mode.ignored = ignored --local grammar = { -- [1] = mode.initialObject and (ignored * (object_type + array_type)) or value_type --} local lexer for _, mod in ipairs(loadedModules) do local new_lexer = mod.generateLexer(mode) lexer = lexer and lexer + new_lexer or new_lexer end return generateDecoder(lexer, mode) end -- Since 'default' is nil, we cannot take map it local defaultDecoder = buildDecoder(json_decode.default) local prebuilt_decoders = {} for _, mode in pairs(modes_defined) do if json_decode[mode] ~= nil then prebuilt_decoders[json_decode[mode]] = buildDecoder(json_decode[mode]) end end --[[ Options: number => number decode options string => string decode options array => array decode options object => object decode options initialObject => whether or not to require the initial object to be a table/array allowUndefined => whether or not to allow undefined values ]] local function getDecoder(mode) mode = mode == true and json_decode.strict or mode or json_decode.default local decoder = mode == nil and defaultDecoder or prebuilt_decoders[mode] if decoder then return decoder end return buildDecoder(mode) end local function decode(data, mode) local decoder = getDecoder(mode) return decoder(data) end local mt = {} mt.__call = function(self, ...) return decode(...) end json_decode.getDecoder = getDecoder json_decode.decode = decode json_decode.util = util setmetatable(json_decode, mt) return json_decode lua-json-1.3.3/lua/json/decode/000077500000000000000000000000001256417601700162345ustar00rootroot00000000000000lua-json-1.3.3/lua/json/decode/composite.lua000066400000000000000000000105571256417601700207510ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local pairs = pairs local type = type local lpeg = require("lpeg") local util = require("json.decode.util") local jsonutil = require("json.util") local rawset = rawset local assert = assert local tostring = tostring local error = error local getmetatable = getmetatable local _ENV = nil local defaultOptions = { array = { trailingComma = true }, object = { trailingComma = true, number = true, identifier = true, setObjectKey = rawset }, calls = { defs = nil, -- By default, do not allow undefined calls to be de-serialized as call objects allowUndefined = false } } local modeOptions = { default = nil, strict = { array = { trailingComma = false }, object = { trailingComma = false, number = false, identifier = false } } } local function BEGIN_ARRAY(state) state:push() state:new_array() end local function END_ARRAY(state) state:end_array() state:pop() end local function BEGIN_OBJECT(state) state:push() state:new_object() end local function END_OBJECT(state) state:end_object() state:pop() end local function END_CALL(state) state:end_call() state:pop() end local function SET_KEY(state) state:set_key() end local function NEXT_VALUE(state) state:put_value() end local function mergeOptions(options, mode) jsonutil.doOptionMerge(options, true, 'array', defaultOptions, mode and modeOptions[mode]) jsonutil.doOptionMerge(options, true, 'object', defaultOptions, mode and modeOptions[mode]) jsonutil.doOptionMerge(options, true, 'calls', defaultOptions, mode and modeOptions[mode]) end local isPattern if lpeg.type then function isPattern(value) return lpeg.type(value) == 'pattern' end else local metaAdd = getmetatable(lpeg.P("")).__add function isPattern(value) return getmetatable(value).__add == metaAdd end end local function generateSingleCallLexer(name, func) if type(name) ~= 'string' and not isPattern(name) then error("Invalid functionCalls name: " .. tostring(name) .. " not a string or LPEG pattern") end -- Allow boolean or function to match up w/ encoding permissions if type(func) ~= 'boolean' and type(func) ~= 'function' then error("Invalid functionCalls item: " .. name .. " not a function") end local function buildCallCapture(name) return function(state) if func == false then error("Function call on '" .. name .. "' not permitted") end state:push() state:new_call(name, func) end end local nameCallCapture if type(name) == 'string' then nameCallCapture = lpeg.P(name .. "(") * lpeg.Cc(name) / buildCallCapture else -- Name matcher expected to produce a capture nameCallCapture = name * "(" / buildCallCapture end -- Call func over nameCallCapture and value to permit function receiving name return nameCallCapture end local function generateNamedCallLexers(options) if not options.calls or not options.calls.defs then return end local callCapture for name, func in pairs(options.calls.defs) do local newCapture = generateSingleCallLexer(name, func) if not callCapture then callCapture = newCapture else callCapture = callCapture + newCapture end end return callCapture end local function generateCallLexer(options) local lexer local namedCapture = generateNamedCallLexers(options) if options.calls and options.calls.allowUndefined then lexer = generateSingleCallLexer(lpeg.C(util.identifier), true) end if namedCapture then lexer = lexer and lexer + namedCapture or namedCapture end if lexer then lexer = lexer + lpeg.P(")") * lpeg.Cc(END_CALL) end return lexer end local function generateLexer(options) local ignored = options.ignored local array_options, object_options = options.array, options.object local lexer = lpeg.P("[") * lpeg.Cc(BEGIN_ARRAY) + lpeg.P("]") * lpeg.Cc(END_ARRAY) + lpeg.P("{") * lpeg.Cc(BEGIN_OBJECT) + lpeg.P("}") * lpeg.Cc(END_OBJECT) + lpeg.P(":") * lpeg.Cc(SET_KEY) + lpeg.P(",") * lpeg.Cc(NEXT_VALUE) if object_options.identifier then -- Add identifier match w/ validation check that it is in key lexer = lexer + lpeg.C(util.identifier) * ignored * lpeg.P(":") * lpeg.Cc(SET_KEY) end local callLexers = generateCallLexer(options) if callLexers then lexer = lexer + callLexers end return lexer end local composite = { mergeOptions = mergeOptions, generateLexer = generateLexer } return composite lua-json-1.3.3/lua/json/decode/number.lua000066400000000000000000000045321256417601700202330ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local lpeg = require("lpeg") local tonumber = tonumber local jsonutil = require("json.util") local merge = jsonutil.merge local util = require("json.decode.util") local _ENV = nil local digit = lpeg.R("09") local digits = digit^1 -- Illegal octal declaration local illegal_octal_detect = #(lpeg.P('0') * digits) * util.denied("Octal numbers") local int = (lpeg.P('-') + 0) * (lpeg.R("19") * digits + illegal_octal_detect + digit) local frac = lpeg.P('.') * digits local exp = lpeg.S("Ee") * (lpeg.S("-+") + 0) * digits local nan = lpeg.S("Nn") * lpeg.S("Aa") * lpeg.S("Nn") local inf = lpeg.S("Ii") * lpeg.P("nfinity") local ninf = lpeg.P('-') * lpeg.S("Ii") * lpeg.P("nfinity") local hex = (lpeg.P("0x") + lpeg.P("0X")) * lpeg.R("09","AF","af")^1 local defaultOptions = { nan = true, inf = true, frac = true, exp = true, hex = false } local modeOptions = {} modeOptions.strict = { nan = false, inf = false } local nan_value = 0/0 local inf_value = 1/0 local ninf_value = -1/0 --[[ Options: configuration options for number rules nan: match NaN inf: match Infinity frac: match fraction portion (.0) exp: match exponent portion (e1) DEFAULT: nan, inf, frac, exp ]] local function mergeOptions(options, mode) jsonutil.doOptionMerge(options, false, 'number', defaultOptions, mode and modeOptions[mode]) end local function generateLexer(options) options = options.number local ret = int if options.frac then ret = ret * (frac + 0) else ret = ret * (#frac * util.denied("Fractions", "number.frac") + 0) end if options.exp then ret = ret * (exp + 0) else ret = ret * (#exp * util.denied("Exponents", "number.exp") + 0) end if options.hex then ret = hex + ret else ret = #hex * util.denied("Hexadecimal", "number.hex") + ret end -- Capture number now ret = ret / tonumber if options.nan then ret = ret + nan / function() return nan_value end else ret = ret + #nan * util.denied("NaN", "number.nan") end if options.inf then ret = ret + ninf / function() return ninf_value end + inf / function() return inf_value end else ret = ret + (#ninf + #inf) * util.denied("+/-Inf", "number.inf") end return ret end local number = { int = int, mergeOptions = mergeOptions, generateLexer = generateLexer } return number lua-json-1.3.3/lua/json/decode/others.lua000066400000000000000000000031001256417601700202350ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local lpeg = require("lpeg") local jsonutil = require("json.util") local merge = jsonutil.merge local util = require("json.decode.util") -- Container module for other JavaScript types (bool, null, undefined) local _ENV = nil -- For null and undefined, use the util.null value to preserve null-ness local booleanCapture = lpeg.P("true") * lpeg.Cc(true) + lpeg.P("false") * lpeg.Cc(false) local nullCapture = lpeg.P("null") local undefinedCapture = lpeg.P("undefined") local defaultOptions = { allowUndefined = true, null = jsonutil.null, undefined = jsonutil.undefined } local modeOptions = {} modeOptions.simple = { null = false, -- Mapped to nil undefined = false -- Mapped to nil } modeOptions.strict = { allowUndefined = false } local function mergeOptions(options, mode) jsonutil.doOptionMerge(options, false, 'others', defaultOptions, mode and modeOptions[mode]) end local function generateLexer(options) -- The 'or nil' clause allows false to map to a nil value since 'nil' cannot be merged options = options.others local valueCapture = ( booleanCapture + nullCapture * lpeg.Cc(options.null or nil) ) if options.allowUndefined then valueCapture = valueCapture + undefinedCapture * lpeg.Cc(options.undefined or nil) else valueCapture = valueCapture + #undefinedCapture * util.denied("undefined", "others.allowUndefined") end return valueCapture end local others = { mergeOptions = mergeOptions, generateLexer = generateLexer } return others lua-json-1.3.3/lua/json/decode/state.lua000066400000000000000000000102451256417601700200610ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local setmetatable = setmetatable local jsonutil = require("json.util") local assert = assert local type = type local next = next local unpack = unpack local _ENV = nil local state_ops = {} local state_mt = { __index = state_ops } function state_ops.pop(self) self.previous_set = true self.previous = self.active local i = self.i -- Load in this array into the active item self.active = self.stack[i] self.active_state = self.state_stack[i] self.active_key = self.key_stack[i] self.stack[i] = nil self.state_stack[i] = nil self.key_stack[i] = nil self.i = i - 1 end function state_ops.push(self) local i = self.i + 1 self.i = i self.stack[i] = self.active self.state_stack[i] = self.active_state self.key_stack[i] = self.active_key end function state_ops.put_object_value(self, trailing) local object_options = self.options.object if trailing and object_options.trailingComma then if not self.active_key then return end end assert(self.active_key, "Missing key value") object_options.setObjectKey(self.active, self.active_key, self:grab_value()) self.active_key = nil end function state_ops.put_array_value(self, trailing) -- Safety check if trailing and not self.previous_set and self.options.array.trailingComma then return end local new_index = self.active_state + 1 self.active_state = new_index self.active[new_index] = self:grab_value() end function state_ops.put_value(self, trailing) if self.active_state == 'object' then self:put_object_value(trailing) else self:put_array_value(trailing) end end function state_ops.new_array(self) local new_array = {} if jsonutil.InitArray then new_array = jsonutil.InitArray(new_array) or new_array end self.active = new_array self.active_state = 0 self.active_key = nil self:unset_value() end function state_ops.end_array(self) if self.previous_set or self.active_state ~= 0 then -- Not an empty array self:put_value(true) end if self.active_state ~= #self.active then -- Store the length in self.active.n = self.active_state end end function state_ops.new_object(self) local new_object = {} self.active = new_object self.active_state = 'object' self.active_key = nil self:unset_value() end function state_ops.end_object(self) if self.previous_set or next(self.active) then -- Not an empty object self:put_value(true) end end function state_ops.new_call(self, name, func) -- TODO setup properly local new_call = {} new_call.name = name new_call.func = func self.active = new_call self.active_state = 0 self.active_key = nil self:unset_value() end function state_ops.end_call(self) if self.previous_set or self.active_state ~= 0 then -- Not an empty array self:put_value(true) end if self.active_state ~= #self.active then -- Store the length in self.active.n = self.active_state end local func = self.active.func if func == true then func = jsonutil.buildCall end self.active = func(self.active.name, unpack(self.active, 1, self.active.n or #self.active)) end function state_ops.unset_value(self) self.previous_set = false self.previous = nil end function state_ops.grab_value(self) assert(self.previous_set, "Previous value not set") self.previous_set = false return self.previous end function state_ops.set_value(self, value) assert(not self.previous_set, "Value set when one already in slot") self.previous_set = true self.previous = value end function state_ops.set_key(self) assert(self.active_state == 'object', "Cannot set key on array") local value = self:grab_value() local value_type = type(value) if self.options.object.number then assert(value_type == 'string' or value_type == 'number', "As configured, a key must be a number or string") else assert(value_type == 'string', "As configured, a key must be a string") end self.active_key = value end local function create(options) local ret = { options = options, stack = {}, state_stack = {}, key_stack = {}, i = 0, active = nil, active_key = nil, previous = nil, active_state = nil } return setmetatable(ret, state_mt) end local state = { create = create } return state lua-json-1.3.3/lua/json/decode/strings.lua000066400000000000000000000071731256417601700204400ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local lpeg = require("lpeg") local jsonutil = require("json.util") local util = require("json.decode.util") local merge = jsonutil.merge local tonumber = tonumber local string_char = require("string").char local floor = require("math").floor local table_concat = require("table").concat local error = error local _ENV = nil local function get_error(item) local fmt_string = item .. " in string [%q] @ %i:%i" return lpeg.P(function(data, index) local line, line_index, bad_char, last_line = util.get_invalid_character_info(data, index) local err = fmt_string:format(bad_char, line, line_index) error(err) end) * 1 end local bad_unicode = get_error("Illegal unicode escape") local bad_hex = get_error("Illegal hex escape") local bad_character = get_error("Illegal character") local bad_escape = get_error("Illegal escape") local knownReplacements = { ["'"] = "'", ['"'] = '"', ['\\'] = '\\', ['/'] = '/', b = '\b', f = '\f', n = '\n', r = '\r', t = '\t', v = '\v', z = '\z' } -- according to the table at http://da.wikipedia.org/wiki/UTF-8 local function utf8DecodeUnicode(code1, code2) code1, code2 = tonumber(code1, 16), tonumber(code2, 16) if code1 == 0 and code2 < 0x80 then return string_char(code2) end if code1 < 0x08 then return string_char( 0xC0 + code1 * 4 + floor(code2 / 64), 0x80 + code2 % 64) end return string_char( 0xE0 + floor(code1 / 16), 0x80 + (code1 % 16) * 4 + floor(code2 / 64), 0x80 + code2 % 64) end local function decodeX(code) code = tonumber(code, 16) return string_char(code) end local doSimpleSub = lpeg.C(lpeg.S("'\"\\/bfnrtvz")) / knownReplacements local doUniSub = lpeg.P('u') * (lpeg.C(util.hexpair) * lpeg.C(util.hexpair) + bad_unicode) local doXSub = lpeg.P('x') * (lpeg.C(util.hexpair) + bad_hex) local defaultOptions = { badChars = '', additionalEscapes = false, -- disallow untranslated escapes escapeCheck = #lpeg.S('bfnrtv/\\"xu\'z'), -- no check on valid characters decodeUnicode = utf8DecodeUnicode, strict_quotes = false } local modeOptions = {} modeOptions.strict = { badChars = '\b\f\n\r\t\v', additionalEscapes = false, -- no additional escapes escapeCheck = #lpeg.S('bfnrtv/\\"u'), --only these chars are allowed to be escaped strict_quotes = true } local function mergeOptions(options, mode) jsonutil.doOptionMerge(options, false, 'strings', defaultOptions, mode and modeOptions[mode]) end local function buildCaptureString(quote, badChars, escapeMatch) local captureChar = (1 - lpeg.S("\\" .. badChars .. quote)) + (lpeg.P("\\") / "" * escapeMatch) -- During error, force end local captureString = captureChar^0 + (-#lpeg.P(quote) * bad_character + -1) return lpeg.P(quote) * lpeg.Cs(captureString) * lpeg.P(quote) end local function generateLexer(options) options = options.strings local quotes = { '"' } if not options.strict_quotes then quotes[#quotes + 1] = "'" end local escapeMatch = doSimpleSub escapeMatch = escapeMatch + doXSub / decodeX escapeMatch = escapeMatch + doUniSub / options.decodeUnicode if options.additionalEscapes then escapeMatch = escapeMatch + options.additionalEscapes end if options.escapeCheck then escapeMatch = options.escapeCheck * escapeMatch + bad_escape end local captureString for i = 1, #quotes do local cap = buildCaptureString(quotes[i], options.badChars, escapeMatch) if captureString == nil then captureString = cap else captureString = captureString + cap end end return captureString end local strings = { mergeOptions = mergeOptions, generateLexer = generateLexer } return strings lua-json-1.3.3/lua/json/decode/util.lua000066400000000000000000000071701256417601700177210ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local lpeg = require("lpeg") local select = select local pairs, ipairs = pairs, ipairs local tonumber = tonumber local string_char = require("string").char local rawset = rawset local jsonutil = require("json.util") local error = error local setmetatable = setmetatable local table_concat = require("table").concat local merge = require("json.util").merge local _ENV = nil local function get_invalid_character_info(input, index) local parsed = input:sub(1, index) local bad_character = input:sub(index, index) local _, line_number = parsed:gsub('\n',{}) local last_line = parsed:match("\n([^\n]+.)$") or parsed return line_number, #last_line, bad_character, last_line end local function build_report(msg) local fmt = msg:gsub("%%", "%%%%") .. " @ character: %i %i:%i [%s] line:\n%s" return lpeg.P(function(data, pos) local line, line_index, bad_char, last_line = get_invalid_character_info(data, pos) local text = fmt:format(pos, line, line_index, bad_char, last_line) error(text) end) * 1 end local function unexpected() local msg = "unexpected character" return build_report(msg) end local function expected(...) local items = {...} local msg if #items > 1 then msg = "expected one of '" .. table_concat(items, "','") .. "'" else msg = "expected '" .. items[1] .. "'" end return build_report(msg) end local function denied(item, option) local msg if option then msg = ("'%s' denied by option set '%s'"):format(item, option) else msg = ("'%s' denied"):format(item) end return build_report(msg) end -- 09, 0A, 0B, 0C, 0D, 20 local ascii_space = lpeg.S("\t\n\v\f\r ") local unicode_space do local chr = string_char local u_space = ascii_space -- \u0085 \u00A0 u_space = u_space + lpeg.P(chr(0xC2)) * lpeg.S(chr(0x85) .. chr(0xA0)) -- \u1680 \u180E u_space = u_space + lpeg.P(chr(0xE1)) * (lpeg.P(chr(0x9A, 0x80)) + chr(0xA0, 0x8E)) -- \u2000 - \u200A, also 200B local spacing_end = "" for i = 0x80,0x8b do spacing_end = spacing_end .. chr(i) end -- \u2028 \u2029 \u202F spacing_end = spacing_end .. chr(0xA8) .. chr(0xA9) .. chr(0xAF) u_space = u_space + lpeg.P(chr(0xE2, 0x80)) * lpeg.S(spacing_end) -- \u205F u_space = u_space + lpeg.P(chr(0xE2, 0x81, 0x9F)) -- \u3000 u_space = u_space + lpeg.P(chr(0xE3, 0x80, 0x80)) -- BOM \uFEFF u_space = u_space + lpeg.P(chr(0xEF, 0xBB, 0xBF)) unicode_space = u_space end local identifier = lpeg.R("AZ","az","__") * lpeg.R("AZ","az", "__", "09") ^0 local hex = lpeg.R("09","AF","af") local hexpair = hex * hex local comments = { cpp = lpeg.P("//") * (1 - lpeg.P("\n"))^0 * lpeg.P("\n"), c = lpeg.P("/*") * (1 - lpeg.P("*/"))^0 * lpeg.P("*/") } local comment = comments.cpp + comments.c local ascii_ignored = (ascii_space + comment)^0 local unicode_ignored = (unicode_space + comment)^0 -- Parse the lpeg version skipping patch-values -- LPEG <= 0.7 have no version value... so 0.7 is value local DecimalLpegVersion = lpeg.version and tonumber(lpeg.version():match("^(%d+%.%d+)")) or 0.7 local function setObjectKeyForceNumber(t, key, value) key = tonumber(key) or key return rawset(t, key, value) end local util = { unexpected = unexpected, expected = expected, denied = denied, ascii_space = ascii_space, unicode_space = unicode_space, identifier = identifier, hex = hex, hexpair = hexpair, comments = comments, comment = comment, ascii_ignored = ascii_ignored, unicode_ignored = unicode_ignored, DecimalLpegVersion = DecimalLpegVersion, get_invalid_character_info = get_invalid_character_info, setObjectKeyForceNumber = setObjectKeyForceNumber } return util lua-json-1.3.3/lua/json/encode.lua000066400000000000000000000106511256417601700167540ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local type = type local assert, error = assert, error local getmetatable, setmetatable = getmetatable, setmetatable local ipairs, pairs = ipairs, pairs local require = require local output = require("json.encode.output") local util = require("json.util") local util_merge, isCall = util.merge, util.isCall local _ENV = nil --[[ List of encoding modules to load. Loaded in sequence such that earlier encoders get priority when duplicate type-handlers exist. ]] local modulesToLoad = { "strings", "number", "calls", "others", "array", "object" } -- Modules that have been loaded local loadedModules = {} local json_encode = {} -- Configuration bases for client apps local modes_defined = { "default", "strict" } json_encode.default = {} json_encode.strict = { initialObject = true -- Require an object at the root } -- For each module, load it and its defaults for _,name in ipairs(modulesToLoad) do local mod = require("json.encode." .. name) if mod.mergeOptions then for _, mode in pairs(modes_defined) do mod.mergeOptions(json_encode[mode], mode) end end loadedModules[name] = mod end -- Merges values, assumes all tables are arrays, inner values flattened, optionally constructing output local function flattenOutput(out, values) out = not out and {} or type(out) == 'table' and out or {out} if type(values) == 'table' then for _, v in ipairs(values) do out[#out + 1] = v end else out[#out + 1] = values end return out end -- Prepares the encoding map from the already provided modules and new config local function prepareEncodeMap(options) local map = {} for _, name in ipairs(modulesToLoad) do local encodermap = loadedModules[name].getEncoder(options[name]) for valueType, encoderSet in pairs(encodermap) do map[valueType] = flattenOutput(map[valueType], encoderSet) end end return map end --[[ Encode a value with a given encoding map and state ]] local function encodeWithMap(value, map, state, isObjectKey) local t = type(value) local encoderList = assert(map[t], "Failed to encode value, unhandled type: " .. t) for _, encoder in ipairs(encoderList) do local ret = encoder(value, state, isObjectKey) if false ~= ret then return ret end end error("Failed to encode value, encoders for " .. t .. " deny encoding") end local function getBaseEncoder(options) local encoderMap = prepareEncodeMap(options) if options.preProcess then local preProcess = options.preProcess return function(value, state, isObjectKey) local ret = preProcess(value, isObjectKey or false) if nil ~= ret then value = ret end return encodeWithMap(value, encoderMap, state) end end return function(value, state, isObjectKey) return encodeWithMap(value, encoderMap, state) end end --[[ Retreive an initial encoder instance based on provided options the initial encoder is responsible for initializing state State has at least these values configured: encode, check_unique, already_encoded ]] function json_encode.getEncoder(options) options = options and util_merge({}, json_encode.default, options) or json_encode.default local encode = getBaseEncoder(options) local function initialEncode(value) if options.initialObject then local errorMessage = "Invalid arguments: expects a JSON Object or Array at the root" assert(type(value) == 'table' and not isCall(value, options), errorMessage) end local alreadyEncoded = {} local function check_unique(value) assert(not alreadyEncoded[value], "Recursive encoding of value") alreadyEncoded[value] = true end local outputEncoder = options.output and options.output() or output.getDefault() local state = { encode = encode, check_unique = check_unique, already_encoded = alreadyEncoded, -- To unmark encoding when moving up stack outputEncoder = outputEncoder } local ret = encode(value, state) if nil ~= ret then return outputEncoder.simple and outputEncoder.simple(ret) or ret end end return initialEncode end -- CONSTRUCT STATE WITH FOLLOWING (at least) --[[ encoder check_unique -- used by inner encoders to make sure value is unique already_encoded -- used to unmark a value as unique ]] function json_encode.encode(data, options) return json_encode.getEncoder(options)(data) end local mt = {} mt.__call = function(self, ...) return json_encode.encode(...) end setmetatable(json_encode, mt) return json_encode lua-json-1.3.3/lua/json/encode/000077500000000000000000000000001256417601700162465ustar00rootroot00000000000000lua-json-1.3.3/lua/json/encode/array.lua000066400000000000000000000053221256417601700200710ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local jsonutil = require("json.util") local type = type local pairs = pairs local assert = assert local table = require("table") local math = require("math") local table_concat = table.concat local math_floor, math_modf = math.floor, math.modf local jsonutil = require("json.util") local util_IsArray = jsonutil.IsArray local _ENV = nil local defaultOptions = { isArray = util_IsArray } local modeOptions = {} local function mergeOptions(options, mode) jsonutil.doOptionMerge(options, false, 'array', defaultOptions, mode and modeOptions[mode]) end --[[ Utility function to determine whether a table is an array or not. Criteria for it being an array: * ExternalIsArray returns true (or false directly reports not-array) * If the table has an 'n' value that is an integer >= 1 then it is an array... may result in false positives (should check some values before it) * It is a contiguous list of values with zero string-based keys ]] local function isArray(val, options) local externalIsArray = options and options.isArray if externalIsArray then local ret = externalIsArray(val) if ret == true or ret == false then return ret end end -- Use the 'n' element if it's a number if type(val.n) == 'number' and math_floor(val.n) == val.n and val.n >= 1 then return true end local len = #val for k,v in pairs(val) do if type(k) ~= 'number' then return false end local _, decim = math_modf(k) if not (decim == 0 and 1<=k) then return false end if k > len then -- Use Lua's length as absolute determiner return false end end return true end --[[ Cleanup function to unmark a value as in the encoding process and return trailing results ]] local function unmarkAfterEncode(tab, state, ...) state.already_encoded[tab] = nil return ... end local function getEncoder(options) options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions local function encodeArray(tab, state) if not isArray(tab, options) then return false end -- Make sure this value hasn't been encoded yet state.check_unique(tab) local encode = state.encode local compositeEncoder = state.outputEncoder.composite local valueEncoder = [[ for i = 1, (composite.n or #composite) do local val = composite[i] PUTINNER(i ~= 1) val = encode(val, state) val = val or '' if val then PUTVALUE(val) end end ]] return unmarkAfterEncode(tab, state, compositeEncoder(valueEncoder, '[', ']', ',', tab, encode, state)) end return { table = encodeArray } end local array = { mergeOptions = mergeOptions, isArray = isArray, getEncoder = getEncoder } return array lua-json-1.3.3/lua/json/encode/calls.lua000066400000000000000000000031431256417601700200500ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local table = require("table") local table_concat = table.concat local select = select local getmetatable, setmetatable = getmetatable, setmetatable local assert = assert local jsonutil = require("json.util") local isCall, decodeCall = jsonutil.isCall, jsonutil.decodeCall local _ENV = nil local defaultOptions = { } -- No real default-option handling needed... local modeOptions = {} local function mergeOptions(options, mode) jsonutil.doOptionMerge(options, false, 'calls', defaultOptions, mode and modeOptions[mode]) end --[[ Encodes 'value' as a function call Must have parameters in the 'callData' field of the metatable name == name of the function call parameters == array of parameters to encode ]] local function getEncoder(options) options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions local function encodeCall(value, state) if not isCall(value) then return false end local encode = state.encode local name, params = decodeCall(value) local compositeEncoder = state.outputEncoder.composite local valueEncoder = [[ for i = 1, (composite.n or #composite) do local val = composite[i] PUTINNER(i ~= 1) val = encode(val, state) val = val or '' if val then PUTVALUE(val) end end ]] return compositeEncoder(valueEncoder, name .. '(', ')', ',', params, encode, state) end return { table = encodeCall, ['function'] = encodeCall } end local calls = { mergeOptions = mergeOptions, getEncoder = getEncoder } return calls lua-json-1.3.3/lua/json/encode/number.lua000066400000000000000000000023201256417601700202360ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local tostring = tostring local assert = assert local jsonutil = require("json.util") local huge = require("math").huge local _ENV = nil local defaultOptions = { nan = true, inf = true } local modeOptions = {} modeOptions.strict = { nan = false, inf = false } local function mergeOptions(options, mode) jsonutil.doOptionMerge(options, false, 'number', defaultOptions, mode and modeOptions[mode]) end local function encodeNumber(number, options) if number ~= number then assert(options.nan, "Invalid number: NaN not enabled") return "NaN" end if number == huge then assert(options.inf, "Invalid number: Infinity not enabled") return "Infinity" end if number == -huge then assert(options.inf, "Invalid number: Infinity not enabled") return "-Infinity" end return tostring(number) end local function getEncoder(options) options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions return { number = function(number, state) return encodeNumber(number, options) end } end local number = { mergeOptions = mergeOptions, getEncoder = getEncoder } return number lua-json-1.3.3/lua/json/encode/object.lua000066400000000000000000000034541256417601700202250ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local pairs = pairs local assert = assert local type = type local tostring = tostring local table_concat = require("table").concat local jsonutil = require("json.util") local _ENV = nil local defaultOptions = { } local modeOptions = {} local function mergeOptions(options, mode) jsonutil.doOptionMerge(options, false, 'object', defaultOptions, mode and modeOptions[mode]) end --[[ Cleanup function to unmark a value as in the encoding process and return trailing results ]] local function unmarkAfterEncode(tab, state, ...) state.already_encoded[tab] = nil return ... end --[[ Encode a table as a JSON Object ( keys = strings, values = anything else ) ]] local function encodeTable(tab, options, state) -- Make sure this value hasn't been encoded yet state.check_unique(tab) local encode = state.encode local compositeEncoder = state.outputEncoder.composite local valueEncoder = [[ local first = true for k, v in pairs(composite) do local ti = type(k) assert(ti == 'string' or ti == 'number' or ti == 'boolean', "Invalid object index type: " .. ti) local name = encode(tostring(k), state, true) if first then first = false else name = ',' .. name end PUTVALUE(name .. ':') local val = encode(v, state) val = val or '' if val then PUTVALUE(val) end end ]] return unmarkAfterEncode(tab, state, compositeEncoder(valueEncoder, '{', '}', nil, tab, encode, state)) end local function getEncoder(options) options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions return { table = function(tab, state) return encodeTable(tab, options, state) end } end local object = { mergeOptions = mergeOptions, getEncoder = getEncoder } return object lua-json-1.3.3/lua/json/encode/others.lua000066400000000000000000000030511256417601700202540ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local tostring = tostring local assert = assert local jsonutil = require("json.util") local type = type local _ENV = nil -- Shortcut that works local encodeBoolean = tostring local defaultOptions = { allowUndefined = true, null = jsonutil.null, undefined = jsonutil.undefined } local modeOptions = {} modeOptions.strict = { allowUndefined = false } local function mergeOptions(options, mode) jsonutil.doOptionMerge(options, false, 'others', defaultOptions, mode and modeOptions[mode]) end local function getEncoder(options) options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions local function encodeOthers(value, state) if value == options.null then return 'null' elseif value == options.undefined then assert(options.allowUndefined, "Invalid value: Unsupported 'Undefined' parameter") return 'undefined' else return false end end local function encodeBoolean(value, state) return value and 'true' or 'false' end local nullType = type(options.null) local undefinedType = options.undefined and type(options.undefined) -- Make sure that all of the types handled here are handled local ret = { boolean = encodeBoolean, ['nil'] = function() return 'null' end, [nullType] = encodeOthers } if undefinedType then ret[undefinedType] = encodeOthers end return ret end local others = { encodeBoolean = encodeBoolean, mergeOptions = mergeOptions, getEncoder = getEncoder } return others lua-json-1.3.3/lua/json/encode/output.lua000066400000000000000000000045441256417601700203200ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local type = type local assert, error = assert, error local table_concat = require("table").concat local loadstring = loadstring or load local io = require("io") local setmetatable = setmetatable local output_utility = require("json.encode.output_utility") local _ENV = nil local tableCompositeCache = setmetatable({}, {__mode = 'v'}) local TABLE_VALUE_WRITER = [[ ret[#ret + 1] = %VALUE% ]] local TABLE_INNER_WRITER = "" --[[ nextValues can output a max of two values to throw into the data stream expected to be called until nil is first return value value separator should either be attached to v1 or in innerValue ]] local function defaultTableCompositeWriter(nextValues, beginValue, closeValue, innerValue, composite, encode, state) if type(nextValues) == 'string' then local fun = output_utility.prepareEncoder(defaultTableCompositeWriter, nextValues, innerValue, TABLE_VALUE_WRITER, TABLE_INNER_WRITER) local ret = {} fun(composite, ret, encode, state) return beginValue .. table_concat(ret, innerValue) .. closeValue end end -- no 'simple' as default action is just to return the value local function getDefault() return { composite = defaultTableCompositeWriter } end -- BEGIN IO-WRITER OUTPUT local IO_INNER_WRITER = [[ if %WRITE_INNER% then state.__outputFile:write(%INNER_VALUE%) end ]] local IO_VALUE_WRITER = [[ state.__outputFile:write(%VALUE%) ]] local function buildIoWriter(output) if not output then -- Default to stdout output = io.output() end local function ioWriter(nextValues, beginValue, closeValue, innerValue, composite, encode, state) -- HOOK OUTPUT STATE state.__outputFile = output if type(nextValues) == 'string' then local fun = output_utility.prepareEncoder(ioWriter, nextValues, innerValue, IO_VALUE_WRITER, IO_INNER_WRITER) local ret = {} output:write(beginValue) fun(composite, ret, encode, state) output:write(closeValue) return nil end end local function ioSimpleWriter(encoded) if encoded then output:write(encoded) end return nil end return { composite = ioWriter, simple = ioSimpleWriter } end local function getIoWriter(output) return function() return buildIoWriter(output) end end local output = { getDefault = getDefault, getIoWriter = getIoWriter } return output lua-json-1.3.3/lua/json/encode/output_utility.lua000066400000000000000000000033671256417601700221050ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local setmetatable = setmetatable local assert, loadstring = assert, loadstring or load local _ENV = nil -- Key == weak, if main key goes away, then cache cleared local outputCache = setmetatable({}, {__mode = 'k'}) -- TODO: inner tables weak? local function buildFunction(nextValues, innerValue, valueWriter, innerWriter) local putInner = "" if innerValue and innerWriter then -- Prepare the lua-string representation of the separator to put in between values local formattedInnerValue = ("%q"):format(innerValue) -- Fill in the condition %WRITE_INNER% and the %INNER_VALUE% to actually write putInner = innerWriter:gsub("%%WRITE_INNER%%", "%%1"):gsub("%%INNER_VALUE%%", formattedInnerValue) end -- Template-in the value writer (if present) and its conditional argument local functionCode = nextValues:gsub("PUTINNER(%b())", putInner) -- %VALUE% is to be filled in by the value-to-write valueWriter = valueWriter:gsub("%%VALUE%%", "%%1") -- Template-in the value writer with its argument functionCode = functionCode:gsub("PUTVALUE(%b())", valueWriter) functionCode = [[ return function(composite, ret, encode, state) ]] .. functionCode .. [[ end ]] return assert(loadstring(functionCode))() end local function prepareEncoder(cacheKey, nextValues, innerValue, valueWriter, innerWriter) local cache = outputCache[cacheKey] if not cache then cache = {} outputCache[cacheKey] = cache end local fun = cache[nextValues] if not fun then fun = buildFunction(nextValues, innerValue, valueWriter, innerWriter) cache[nextValues] = fun end return fun end local output_utility = { prepareEncoder = prepareEncoder } return output_utility lua-json-1.3.3/lua/json/encode/strings.lua000066400000000000000000000047401256417601700204470ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local string_char = require("string").char local pairs = pairs local jsonutil = require("json.util") local util_merge = jsonutil.merge local _ENV = nil local normalEncodingMap = { ['"'] = '\\"', ['\\'] = '\\\\', ['/'] = '\\/', ['\b'] = '\\b', ['\f'] = '\\f', ['\n'] = '\\n', ['\r'] = '\\r', ['\t'] = '\\t', ['\v'] = '\\v' -- not in official spec, on report, removing } local xEncodingMap = {} for char, encoded in pairs(normalEncodingMap) do xEncodingMap[char] = encoded end -- Pre-encode the control characters to speed up encoding... -- NOTE: UTF-8 may not work out right w/ JavaScript -- JavaScript uses 2 bytes after a \u... yet UTF-8 is a -- byte-stream encoding, not pairs of bytes (it does encode -- some letters > 1 byte, but base case is 1) for i = 0, 255 do local c = string_char(i) if c:match('[%z\1-\031\128-\255]') and not normalEncodingMap[c] then -- WARN: UTF8 specializes values >= 0x80 as parts of sequences... -- without \x encoding, do not allow encoding > 7F normalEncodingMap[c] = ('\\u%.4X'):format(i) xEncodingMap[c] = ('\\x%.2X'):format(i) end end local defaultOptions = { xEncode = false, -- Encode single-bytes as \xXX processor = nil, -- Simple processor for the string prior to quoting -- / is not required to be quoted but it helps with certain decoding -- Required encoded characters, " \, and 00-1F (0 - 31) encodeSet = '\\"/%z\1-\031', encodeSetAppend = nil -- Chars to append to the default set } local modeOptions = {} local function mergeOptions(options, mode) jsonutil.doOptionMerge(options, false, 'strings', defaultOptions, mode and modeOptions[mode]) end local function getEncoder(options) options = options and util_merge({}, defaultOptions, options) or defaultOptions local encodeSet = options.encodeSet if options.encodeSetAppend then encodeSet = encodeSet .. options.encodeSetAppend end local encodingMap = options.xEncode and xEncodingMap or normalEncodingMap local encodeString if options.processor then local processor = options.processor encodeString = function(s, state) return '"' .. processor(s:gsub('[' .. encodeSet .. ']', encodingMap)) .. '"' end else encodeString = function(s, state) return '"' .. s:gsub('[' .. encodeSet .. ']', encodingMap) .. '"' end end return { string = encodeString } end local strings = { mergeOptions = mergeOptions, getEncoder = getEncoder } return strings lua-json-1.3.3/lua/json/util.lua000066400000000000000000000066771256417601700165110ustar00rootroot00000000000000--[[ Licensed according to the included 'LICENSE' document Author: Thomas Harning Jr ]] local type = type local print = print local tostring = tostring local pairs = pairs local getmetatable, setmetatable = getmetatable, setmetatable local select = select local _ENV = nil local function foreach(tab, func) for k, v in pairs(tab) do func(k,v) end end local function printValue(tab, name) local parsed = {} local function doPrint(key, value, space) space = space or '' if type(value) == 'table' then if parsed[value] then print(space .. key .. '= <' .. parsed[value] .. '>') else parsed[value] = key print(space .. key .. '= {') space = space .. ' ' foreach(value, function(key, value) doPrint(key, value, space) end) end else if type(value) == 'string' then value = '[[' .. tostring(value) .. ']]' end print(space .. key .. '=' .. tostring(value)) end end doPrint(name, tab) end local function clone(t) local ret = {} for k,v in pairs(t) do ret[k] = v end return ret end local function inner_merge(t, remaining, from, ...) if remaining == 0 then return t end if from then for k,v in pairs(from) do t[k] = v end end return inner_merge(t, remaining - 1, ...) end --[[* Shallow-merges tables in order onto the first table. @param t table to merge entries onto @param ... sequence of 0 or more tables to merge onto 't' @returns table 't' from input ]] local function merge(t, ...) return inner_merge(t, select('#', ...), ...) end -- Function to insert nulls into the JSON stream local function null() return null end -- Marker for 'undefined' values local function undefined() return undefined end local ArrayMT = {} --[[ Return's true if the metatable marks it as an array.. Or false if it has no array component at all Otherwise nil to get the normal detection component working ]] local function IsArray(value) if type(value) ~= 'table' then return false end local meta = getmetatable(value) local ret = meta == ArrayMT or (meta ~= nil and meta.__is_luajson_array) if not ret then if #value == 0 then return false end else return ret end end local function InitArray(array) setmetatable(array, ArrayMT) return array end local CallMT = {} local function isCall(value) return CallMT == getmetatable(value) end local function buildCall(name, ...) local callData = { name = name, parameters = {n = select('#', ...), ...} } return setmetatable(callData, CallMT) end local function decodeCall(callData) if not isCall(callData) then return nil end return callData.name, callData.parameters end local function doOptionMerge(options, nested, name, defaultOptions, modeOptions) if nested then modeOptions = modeOptions and modeOptions[name] defaultOptions = defaultOptions and defaultOptions[name] end options[name] = merge( {}, defaultOptions, modeOptions, options[name] ) end local json_util = { printValue = printValue, clone = clone, merge = merge, null = null, undefined = undefined, IsArray = IsArray, InitArray = InitArray, isCall = isCall, buildCall = buildCall, decodeCall = decodeCall, doOptionMerge = doOptionMerge } return json_util lua-json-1.3.3/rockspecs/000077500000000000000000000000001256417601700152535ustar00rootroot00000000000000lua-json-1.3.3/rockspecs/luajson-0.10-1.rockspec000066400000000000000000000026501256417601700211760ustar00rootroot00000000000000package = "luajson" version = "0.10-1" source = { url = "http://luaforge.net/frs/download.php/3637/luajson-0.10.tar.bz2", md5 = "0b6fa5e3a07daabe79241922b0bfda92" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { json = "src/json.lua", ["json.util"] = "src/json/util.lua", ["json.decode"] = "src/json/decode.lua", ["json.decode.array"] = "src/json/decode/array.lua", ["json.decode.calls"] = "src/json/decode/calls.lua", ["json.decode.number"] = "src/json/decode/number.lua", ["json.decode.object"] = "src/json/decode/object.lua", ["json.decode.others"] = "src/json/decode/others.lua", ["json.decode.strings"] = "src/json/decode/strings.lua", ["json.decode.util"] = "src/json/decode/util.lua", ["json.encode"] = "src/json/encode.lua", ["json.encode.array"] = "src/json/encode/array.lua", ["json.encode.calls"] = "src/json/encode/calls.lua", ["json.encode.number"] = "src/json/encode/number.lua", ["json.encode.object"] = "src/json/encode/object.lua", ["json.encode.others"] = "src/json/encode/others.lua", ["json.encode.strings"] = "src/json/encode/strings.lua" } } lua-json-1.3.3/rockspecs/luajson-0.10-2.rockspec000066400000000000000000000026501256417601700211770ustar00rootroot00000000000000package = "luajson" version = "0.10-2" source = { url = "http://luaforge.net/frs/download.php/3893/luajson-0.10.tar.bz2", md5 = "0b6fa5e3a07daabe79241922b0bfda92" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { json = "src/json.lua", ["json.util"] = "src/json/util.lua", ["json.decode"] = "src/json/decode.lua", ["json.decode.array"] = "src/json/decode/array.lua", ["json.decode.calls"] = "src/json/decode/calls.lua", ["json.decode.number"] = "src/json/decode/number.lua", ["json.decode.object"] = "src/json/decode/object.lua", ["json.decode.others"] = "src/json/decode/others.lua", ["json.decode.strings"] = "src/json/decode/strings.lua", ["json.decode.util"] = "src/json/decode/util.lua", ["json.encode"] = "src/json/encode.lua", ["json.encode.array"] = "src/json/encode/array.lua", ["json.encode.calls"] = "src/json/encode/calls.lua", ["json.encode.number"] = "src/json/encode/number.lua", ["json.encode.object"] = "src/json/encode/object.lua", ["json.encode.others"] = "src/json/encode/others.lua", ["json.encode.strings"] = "src/json/encode/strings.lua" } } lua-json-1.3.3/rockspecs/luajson-0.9.1-1.rockspec000066400000000000000000000017451256417601700212710ustar00rootroot00000000000000package = "luajson" version = "0.9.1-1" source = { url = "http://luaforge.net/frs/download.php/3637/luajson-0.9.1.tar.bz2", md5 = "49a6a3b7912a053a2b7ad6bbcf4d3564" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://gitrepo.or.cz/w/luajson.git", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { json = "src/json.lua", ["json.util"] = "src/json/util.lua", ["json.encode"] = "src/json/encode.lua", ["json.decode"] = "src/json/decode.lua", ["json.decode.array"] = "src/json/decode/array.lua", ["json.decode.number"] = "src/json/decode/number.lua", ["json.decode.object"] = "src/json/decode/object.lua", ["json.decode.string"] = "src/json/decode/strings.lua", ["json.decode.util"] = "src/json/decode/util.lua" } } lua-json-1.3.3/rockspecs/luajson-1.0-1.rockspec000066400000000000000000000030551256417601700211160ustar00rootroot00000000000000package = "luajson" version = "1.0-1" source = { url = "http://luaforge.net/frs/download.php/4105/luajson-1.0.tar.bz2", md5 = "0e3ee192f93d40c4947e828668828e91" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json.decode.array"] = "lua/json/decode/array.lua", ["json.decode.calls"] = "lua/json/decode/calls.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.object"] = "lua/json/decode/object.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.decode"] = "lua/json/decode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.encode"] = "lua/json/encode.lua", ["json.util"] = "lua/json/util.lua", ["json"] = "lua/json.lua" } } lua-json-1.3.3/rockspecs/luajson-1.0.1-1.rockspec000066400000000000000000000030611256417601700212520ustar00rootroot00000000000000package = "luajson" version = "1.0.1-1" source = { url = "http://luaforge.net/frs/download.php/4311/luajson-1.0.1.tar.bz2", md5 = "f6d52689e0bc4cbbfffff29308e78812" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json"] = "lua/json.lua", ["json.decode"] = "lua/json/decode.lua", ["json.decode.array"] = "lua/json/decode/array.lua", ["json.decode.calls"] = "lua/json/decode/calls.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.object"] = "lua/json/decode/object.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.encode"] = "lua/json/encode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.util"] = "lua/json/util.lua" } } lua-json-1.3.3/rockspecs/luajson-1.0.3-1.rockspec000066400000000000000000000030611256417601700212540ustar00rootroot00000000000000package = "luajson" version = "1.0.3-1" source = { url = "http://luaforge.net/frs/download.php/4678/luajson-1.0.3.tar.bz2", md5 = "15591a426672f32a639187a425464789" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json"] = "lua/json.lua", ["json.decode"] = "lua/json/decode.lua", ["json.decode.array"] = "lua/json/decode/array.lua", ["json.decode.calls"] = "lua/json/decode/calls.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.object"] = "lua/json/decode/object.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.encode"] = "lua/json/encode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.util"] = "lua/json/util.lua" } } lua-json-1.3.3/rockspecs/luajson-1.1-1.rockspec000066400000000000000000000030551256417601700211170ustar00rootroot00000000000000package = "luajson" version = "1.1-1" source = { url = "http://luaforge.net/frs/download.php/4312/luajson-1.1.tar.bz2", md5 = "9c4d267b7383b54576ed307e451aefa4" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json"] = "lua/json.lua", ["json.decode"] = "lua/json/decode.lua", ["json.decode.array"] = "lua/json/decode/array.lua", ["json.decode.calls"] = "lua/json/decode/calls.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.object"] = "lua/json/decode/object.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.encode"] = "lua/json/encode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.util"] = "lua/json/util.lua" } } lua-json-1.3.3/rockspecs/luajson-1.1.2-1.rockspec000066400000000000000000000030611256417601700212540ustar00rootroot00000000000000package = "luajson" version = "1.1.2-1" source = { url = "http://luaforge.net/frs/download.php/4677/luajson-1.1.2.tar.bz2", md5 = "432925dc0baea4329016e9bc5315e987" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json"] = "lua/json.lua", ["json.decode"] = "lua/json/decode.lua", ["json.decode.array"] = "lua/json/decode/array.lua", ["json.decode.calls"] = "lua/json/decode/calls.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.object"] = "lua/json/decode/object.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.encode"] = "lua/json/encode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.util"] = "lua/json/util.lua" } } lua-json-1.3.3/rockspecs/luajson-1.2-1.rockspec000066400000000000000000000030551256417601700211200ustar00rootroot00000000000000package = "luajson" version = "1.2-1" source = { url = "http://luaforge.net/frs/download.php/4672/luajson-1.2.tar.bz2", md5 = "a80aa3c2d96d73afbf63f7146857e116" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json"] = "lua/json.lua", ["json.decode"] = "lua/json/decode.lua", ["json.decode.array"] = "lua/json/decode/array.lua", ["json.decode.calls"] = "lua/json/decode/calls.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.object"] = "lua/json/decode/object.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.encode"] = "lua/json/encode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.util"] = "lua/json/util.lua" } } lua-json-1.3.3/rockspecs/luajson-1.2.1-1.rockspec000066400000000000000000000030611256417601700212540ustar00rootroot00000000000000package = "luajson" version = "1.2.1-1" source = { url = "http://luaforge.net/frs/download.php/4676/luajson-1.2.1.tar.bz2", md5 = "9efc22baf18b757d7a592376c2113bfd" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json"] = "lua/json.lua", ["json.decode"] = "lua/json/decode.lua", ["json.decode.array"] = "lua/json/decode/array.lua", ["json.decode.calls"] = "lua/json/decode/calls.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.object"] = "lua/json/decode/object.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.encode"] = "lua/json/encode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.util"] = "lua/json/util.lua" } } lua-json-1.3.3/rockspecs/luajson-1.2.2-1.rockspec000066400000000000000000000030611256417601700212550ustar00rootroot00000000000000package = "luajson" version = "1.2.2-1" source = { url = "http://luaforge.net/frs/download.php/4816/luajson-1.2.2.tar.bz2", md5 = "6b2768c4a2b102bf36308c722de4060a" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json"] = "lua/json.lua", ["json.decode"] = "lua/json/decode.lua", ["json.decode.array"] = "lua/json/decode/array.lua", ["json.decode.calls"] = "lua/json/decode/calls.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.object"] = "lua/json/decode/object.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.encode"] = "lua/json/encode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.util"] = "lua/json/util.lua" } } lua-json-1.3.3/rockspecs/luajson-1.3-1.rockspec000066400000000000000000000030041256417601700211130ustar00rootroot00000000000000package = "luajson" version = "1.3-1" source = { url = "http://cloud.github.com/downloads/harningt/luajson/luajson-1.3.tar.gz", md5 = "18a59640119143ea69b3744b467e1a89" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json"] = "lua/json.lua", ["json.decode"] = "lua/json/decode.lua", ["json.decode.composite"] = "lua/json/decode/composite.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.state"] = "lua/json/decode/state.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.encode"] = "lua/json/encode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.util"] = "lua/json/util.lua" } } lua-json-1.3.3/rockspecs/luajson-1.3.1-1.rockspec000066400000000000000000000030161256417601700212550ustar00rootroot00000000000000package = "luajson" version = "1.3.1-1" source = { url = "http://cloud.github.com/downloads/harningt/luajson/luajson-1.3.1.tar.gz", md5 = "1ef4751ea4a6e90f76a599d0b3f928f5" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json"] = "lua/json.lua", ["json.decode"] = "lua/json/decode.lua", ["json.decode.composite"] = "lua/json/decode/composite.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.state"] = "lua/json/decode/state.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.encode"] = "lua/json/encode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.util"] = "lua/json/util.lua" } } lua-json-1.3.3/rockspecs/luajson-1.3.2-1.rockspec000066400000000000000000000027131256417601700212610ustar00rootroot00000000000000package = "luajson" version = "1.3.2-1" source = { url = "git://github.com/harningt/luajson.git", tag = "1.3.2" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json"] = "lua/json.lua", ["json.decode"] = "lua/json/decode.lua", ["json.decode.composite"] = "lua/json/decode/composite.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.state"] = "lua/json/decode/state.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.encode"] = "lua/json/encode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.util"] = "lua/json/util.lua" } } lua-json-1.3.3/rockspecs/luajson-1.3.2-2.rockspec000066400000000000000000000026721256417601700212660ustar00rootroot00000000000000package = "luajson" version = "1.3.2-2" source = { url = "git://github.com/harningt/luajson.git", tag = "1.3.2" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json"] = "lua/json.lua", ["json.decode"] = "lua/json/decode.lua", ["json.decode.composite"] = "lua/json/decode/composite.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.state"] = "lua/json/decode/state.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.encode"] = "lua/json/encode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.util"] = "lua/json/util.lua" } } lua-json-1.3.3/rockspecs/luajson-1.3.3-1.rockspec000066400000000000000000000026721256417601700212660ustar00rootroot00000000000000package = "luajson" version = "1.3.3-1" source = { url = "git://github.com/harningt/luajson.git", tag = "1.3.3" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json"] = "lua/json.lua", ["json.decode"] = "lua/json/decode.lua", ["json.decode.composite"] = "lua/json/decode/composite.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.state"] = "lua/json/decode/state.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.encode"] = "lua/json/encode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.util"] = "lua/json/util.lua" } } lua-json-1.3.3/rockspecs/luajson-scm-1.rockspec000066400000000000000000000016251256417601700214030ustar00rootroot00000000000000package = "luajson" version = "scm-1" source = { url = "git://repo.or.cz/luajson.git" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://gitrepo.or.cz/w/luajson.git", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { json = "src/json.lua", ["json.util"] = "src/json/util.lua", ["json.encode"] = "src/json/encode.lua", ["json.decode"] = "src/json/decode.lua", ["json.decode.array"] = "src/json/decode/array.lua", ["json.decode.number"] = "src/json/decode/number.lua", ["json.decode.object"] = "src/json/decode/object.lua", ["json.decode.string"] = "src/json/decode/strings.lua", ["json.decode.util"] = "src/json/decode/util.lua" } } lua-json-1.3.3/rockspecs/luajson-scm-2.rockspec000066400000000000000000000025431256417601700214040ustar00rootroot00000000000000package = "luajson" version = "scm-1" source = { url = "git://github.com/harningt/luajson.git" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { json = "src/json.lua", ["json.util"] = "src/json/util.lua", ["json.decode"] = "src/json/decode.lua", ["json.decode.array"] = "src/json/decode/array.lua", ["json.decode.calls"] = "src/json/decode/calls.lua", ["json.decode.number"] = "src/json/decode/number.lua", ["json.decode.object"] = "src/json/decode/object.lua", ["json.decode.others"] = "src/json/decode/others.lua", ["json.decode.strings"] = "src/json/decode/strings.lua", ["json.decode.util"] = "src/json/decode/util.lua", ["json.encode"] = "src/json/encode.lua", ["json.encode.array"] = "src/json/encode/array.lua", ["json.encode.calls"] = "src/json/encode/calls.lua", ["json.encode.number"] = "src/json/encode/number.lua", ["json.encode.object"] = "src/json/encode/object.lua", ["json.encode.others"] = "src/json/encode/others.lua", ["json.encode.strings"] = "src/json/encode/strings.lua" } } lua-json-1.3.3/rockspecs/luajson-scm-3.rockspec000066400000000000000000000027521256417601700214070ustar00rootroot00000000000000package = "luajson" version = "scm-3" source = { url = "git://github.com/harningt/luajson.git" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json.decode.array"] = "lua/json/decode/array.lua", ["json.decode.calls"] = "lua/json/decode/calls.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.object"] = "lua/json/decode/object.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.decode"] = "lua/json/decode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.encode"] = "lua/json/encode.lua", ["json.util"] = "lua/json/util.lua", ["json"] = "lua/json.lua" } } lua-json-1.3.3/rockspecs/luajson-scm-4.rockspec000066400000000000000000000026711256417601700214100ustar00rootroot00000000000000package = "luajson" version = "scm-4" source = { url = "git://github.com/harningt/luajson.git" } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lunit >= 0.4", "lpeg >= 0.8.1" } build = { type = "module", modules = { ["json"] = "lua/json.lua", ["json.decode"] = "lua/json/decode.lua", ["json.decode.composite"] = "lua/json/decode/composite.lua", ["json.decode.number"] = "lua/json/decode/number.lua", ["json.decode.others"] = "lua/json/decode/others.lua", ["json.decode.state"] = "lua/json/decode/state.lua", ["json.decode.strings"] = "lua/json/decode/strings.lua", ["json.decode.util"] = "lua/json/decode/util.lua", ["json.encode"] = "lua/json/encode.lua", ["json.encode.array"] = "lua/json/encode/array.lua", ["json.encode.calls"] = "lua/json/encode/calls.lua", ["json.encode.number"] = "lua/json/encode/number.lua", ["json.encode.object"] = "lua/json/encode/object.lua", ["json.encode.others"] = "lua/json/encode/others.lua", ["json.encode.output"] = "lua/json/encode/output.lua", ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", ["json.encode.strings"] = "lua/json/encode/strings.lua", ["json.util"] = "lua/json/util.lua" } } lua-json-1.3.3/tests/000077500000000000000000000000001256417601700144215ustar00rootroot00000000000000lua-json-1.3.3/tests/data.txt000066400000000000000000000125641256417601700161030ustar00rootroot00000000000000{"a317":null,"a50":50,"a108":true,"a482":482,"a397":null,"a228":true,"a193":null,"a58":58,"a71":[],"a2":2,"a376":true,"a46":46,"a337":null,"a366":366,"a239":[],"a347":[],"a388":true,"a424":true,"a386":386,"a387":[],"a81":null,"a49":null,"a60":true,"a496":true,"a346":346,"a497":null,"a328":true,"a370":370,"a427":[],"a194":194,"a269":null,"a354":354,"a265":null,"a454":454,"a276":true,"a494":494,"a96":true,"a392":true,"a492":true,"a273":null,"a339":[],"a491":[],"a490":490,"a266":266,"a37":null,"a489":null,"a447":[],"a488":true,"a487":[],"a486":486,"a278":278,"a149":null,"a59":[],"a103":[],"a153":null,"a395":[],"a357":null,"a483":[],"a481":null,"a480":true,"a51":[],"a479":[],"a299":[],"a127":[],"a123":[],"a467":[],"a475":[],"a474":474,"a173":null,"a82":82,"a165":null,"a244":true,"a375":[],"a472":true,"a377":null,"a471":[],"a83":[],"a147":[],"a87":[],"a456":true,"a315":[],"a145":null,"a249":null,"a406":406,"a40":true,"a29":null,"a468":true,"a114":114,"a128":true,"a409":null,"a355":[],"a293":null,"a48":true,"a476":true,"a227":[],"a466":466,"a267":[],"a465":null,"a464":true,"a463":[],"a92":true,"a237":null,"a76":true,"a462":462,"a461":null,"a275":[],"a139":[],"a460":true,"a247":[],"a97":null,"a459":[],"a174":174,"a458":458,"a415":[],"a172":true,"a457":null,"a301":null,"a295":[],"a39":[],"a34":34,"a291":[],"a116":true,"a202":202,"a255":[],"a200":true,"a433":null,"a35":[],"a407":[],"a470":470,"a212":true,"a126":126,"a292":true,"a62":62,"a134":134,"a321":null,"a455":[],"a222":222,"a143":[],"a175":[],"a136":true,"a198":198,"a63":[],"a120":true,"a67":[],"a452":true,"a437":null,"a450":450,"a156":true,"a195":[],"a201":null,"a44":true,"a449":null,"a155":[],"a391":[],"a89":null,"a105":null,"a351":[],"a300":true,"a28":true,"a45":null,"a135":[],"a426":426,"a1":null,"a448":true,"a144":true,"a72":true,"a340":true,"a56":true,"a446":446,"a125":null,"a90":90,"a182":182,"a73":null,"a343":[],"a211":[],"a444":true,"a443":[],"a442":442,"a245":null,"a441":null,"a440":true,"a15":[],"a439":[],"a364":true,"a402":402,"a246":246,"a132":true,"a99":[],"a14":14,"a451":[],"a324":true,"a91":[],"a78":78,"a176":true,"a382":382,"a109":null,"a435":[],"a434":434,"a66":66,"a110":110,"a166":166,"a336":true,"a422":422,"a432":true,"a431":[],"a47":[],"a190":190,"a43":[],"a430":430,"a356":true,"a283":[],"a429":null,"a25":null,"a361":null,"a428":true,"a80":true,"a69":null,"a305":null,"a146":146,"a196":true,"a333":null,"a24":true,"a425":null,"a500":true,"a3":[],"a423":[],"a186":186,"a88":true,"a421":null,"a36":true,"a350":350,"a52":true,"a389":null,"a171":[],"a236":true,"a325":null,"a411":[],"a298":298,"a57":null,"a204":true,"a181":null,"a349":null,"a418":418,"a138":138,"a169":null,"a417":null,"a416":true,"a414":414,"a413":null,"a79":[],"a319":[],"a412":true,"a124":true,"a75":[],"a394":394,"a384":true,"a408":true,"a118":118,"a405":null,"a268":true,"a231":[],"a279":[],"a27":[],"a404":true,"a23":[],"a306":306,"a271":[],"a401":null,"a289":null,"a400":true,"a150":150,"a399":[],"a398":398,"a22":22,"a238":238,"a281":null,"a396":true,"a84":true,"a484":true,"a393":null,"a493":null,"a390":390,"a178":178,"a419":[],"a85":null,"a5":null,"a133":null,"a499":[],"a218":218,"a162":162,"a368":true,"a235":[],"a379":[],"a410":410,"a260":true,"a383":[],"a436":true,"a33":null,"a335":[],"a371":[],"a141":null,"a290":290,"a220":true,"a380":true,"a32":true,"a338":338,"a381":null,"a142":142,"a374":374,"a140":true,"a373":null,"a372":true,"a119":[],"a101":null,"a205":null,"a197":null,"a55":[],"a159":[],"a495":[],"a261":null,"a187":[],"a129":null,"a30":30,"a318":318,"a369":null,"a329":null,"a223":[],"a160":true,"a158":158,"a252":true,"a148":true,"a121":null,"a304":true,"a241":null,"a365":null,"a26":26,"a438":438,"a168":true,"a111":[],"a363":[],"a64":true,"a362":362,"a360":true,"a151":[],"a216":true,"a219":[],"a21":null,"a191":[],"a100":true,"a65":null,"a359":[],"a7":[],"a192":true,"a312":true,"a102":102,"a188":true,"a234":234,"a131":[],"a189":null,"a17":null,"a353":null,"a112":true,"a352":true,"a13":null,"a420":true,"a348":true,"a313":null,"a179":[],"a122":122,"a345":null,"a12":true,"a344":true,"a18":18,"a342":342,"a251":[],"a303":[],"a341":null,"a378":378,"a334":334,"a157":null,"a130":130,"a332":true,"a331":[],"a330":330,"a10":10,"a367":[],"a327":[],"a326":326,"a323":[],"a322":322,"a225":null,"a86":86,"a316":true,"a177":null,"a314":314,"a358":358,"a311":[],"a185":null,"a310":310,"a309":null,"a217":null,"a206":206,"a115":[],"a164":true,"a240":true,"a208":true,"a403":[],"a302":302,"a9":null,"a257":null,"a478":478,"a297":null,"a296":true,"a294":294,"a161":null,"a307":[],"a287":[],"a286":286,"a285":null,"a20":true,"a284":true,"a282":282,"a280":true,"a485":null,"a152":true,"a277":null,"a274":274,"a272":true,"a270":270,"a264":true,"a263":[],"a77":null,"a106":106,"a154":154,"a167":[],"a215":[],"a308":true,"a98":98,"a94":94,"a70":70,"a74":74,"a11":[],"a256":true,"a254":254,"a253":null,"a19":[],"a207":[],"a95":[],"a262":262,"a250":250,"a248":true,"a184":true,"a243":[],"a242":242,"a385":null,"a41":null,"a233":null,"a68":true,"a232":true,"a230":230,"a229":null,"a209":null,"a226":226,"a320":true,"a224":true,"a16":true,"a221":null,"a54":54,"a117":null,"a113":null,"a38":38,"a259":[],"a137":null,"a214":214,"a213":null,"a183":[],"a469":null,"a107":[],"a163":[],"a61":null,"a93":null,"a42":42,"a453":null,"a203":[],"a199":[],"a445":null,"a31":[],"a210":210,"a6":6,"a477":null,"a258":258,"a104":true,"a4":true,"a180":true,"a498":498,"a170":170,"a473":null,"a288":true,"a8":true,"a53":null} lua-json-1.3.3/tests/dataTest.lua000066400000000000000000000003701256417601700166750ustar00rootroot00000000000000local io = require("io") require("json") local f = io.open("data.txt") local data = f:read('*a') f:close() local opt = (...) local strict = opt and opt:match('--strict') local decode = json.decode.decode for i = 1,1000 do decode(data, strict) end lua-json-1.3.3/tests/dataTest.php000066400000000000000000000001521256417601700167010ustar00rootroot00000000000000 lua-json-1.3.3/tests/hook_require.lua000066400000000000000000000006331256417601700176220ustar00rootroot00000000000000local os = require("os") local old_require = require if os.getenv('LUA_OLD_INIT') then local loadstring = loadstring or load assert(loadstring(os.getenv('LUA_OLD_INIT')))() else require("luarocks.require") end local luarocks_require = require function require(module, ...) if module == "json" or module:match("^json%.") then return old_require(module, ...) end return luarocks_require(module, ...) end lua-json-1.3.3/tests/lunit-calls.lua000066400000000000000000000072031256417601700173550ustar00rootroot00000000000000local lpeg = require("lpeg") local json = require("json") local lunit = require("lunit") local math = require("math") local testutil = require("testutil") local encode = json.encode -- DECODE NOT 'local' due to requirement for testutil to access it decode = json.decode.getDecoder(false) module("lunit-calls", lunit.testcase, package.seeall) function setup() -- Ensure that the decoder is reset _G["decode"] = json.decode.getDecoder(false) end local values = { 0, 1, 0.2, "Hello", true, {hi=true}, {1,2} } function test_identity() local function testFunction(capturedName, ...) assert_equal('call', capturedName) return (...) end local strict = { calls = { defs = { call = testFunction } } } local decode = json.decode.getDecoder(strict) for i, v in ipairs(values) do local str = "call(" .. encode(v) .. ")" local decoded = decode(str) if type(decoded) == 'table' then for k2, v2 in pairs(v) do assert_equal(v2, decoded[k2]) decoded[k2] = nil end assert_nil(next(decoded)) else assert_equal(v, decoded) end end end -- Test for a function that throws function test_function_failure() local function testFunction(...) error("CANNOT CONTINUE") end local strict = { calls = { defs = { call = testFunction } } } local decode = json.decode.getDecoder(strict) for i, v in ipairs(values) do local str = "call(" .. encode(v) .. ")" assert_error(function() decode(str) end) end end -- Test for a function that is not a function function test_not_a_function_fail() local notFunction = { 0/0, 1/0, -1/0, 0, 1, "Hello", {}, coroutine.create(function() end) } for _, v in ipairs(notFunction) do assert_error(function() local strict = { calls = { defs = { call = v }, allowUndefined = false } } json.decode.getDecoder(strict) end) end end function test_not_permitted_fail() local strict = { calls = { defs = { call = false } } } local decoder = json.decode.getDecoder(strict) assert_error(function() decoder("call(1)") end) end function test_permitted() local strict = { calls = { defs = { call = true } } } local decoder = json.decode.getDecoder(strict) assert(decoder("call(1)").name == 'call') end function test_not_defined_fail() local decoder = json.decode.getDecoder({ calls = { allowUndefined = false } }) assert_error(function() decoder("call(1)") end) end function test_not_defined_succeed() local decoder = json.decode.getDecoder({ calls = { allowUndefined = true } }) assert(decoder("call(1)").name == 'call') end -- Test for a name that is not a string function test_name_not_string() local notString = { true, false, 0/0, 1/0, -1/0, 0, 1, {}, function() end, coroutine.create(function() end) } for _, v in ipairs(notString) do assert_error(function() local defs = { [v] = function() end } local strict = { calls = { defs = defs } } json.decode.getDecoder(strict) end) end end -- Test for a name that is a string or a pattern function test_name_matches_string_or_pattern() local matchedValues = { ["mystring"] = "mystring", [lpeg.C(lpeg.P("m") * (lpeg.P("y") + lpeg.P("Y")) * "string")] = "mystring", [lpeg.C(lpeg.P("m") * (lpeg.P("y") + lpeg.P("Y")) * "string")] = "mYstring" } for pattern, value in pairs(matchedValues) do local matched = false local function mustBeCalled(capturedName, ...) assert_equal(value, capturedName) matched = true end matched = false local strict = { calls = { defs = { [pattern] = mustBeCalled } } } json.decode.getDecoder(strict)(value .. "(true)") assert_true(matched, "Value <" .. value .. "> did not match the given pattern") end end lua-json-1.3.3/tests/lunit-depth.lua000066400000000000000000000027421256417601700173660ustar00rootroot00000000000000local lunit = require("lunit") local json = require("json") module("lunit-depth", lunit.testcase, package.seeall) local SAFE_DEPTH = 23 local SAFE_CALL_DEPTH = 31 function test_object_current_max_depth() local root = {} for i = 1, SAFE_DEPTH do root = { x = root } end local encoded = json.encode(root) json.decode(encoded) end function test_array_current_max_depth() local root = {} for i = 1, SAFE_DEPTH do root = { root } end local encoded = json.encode(root) json.decode(encoded) end function test_function_current_max_depth() local root = json.util.buildCall("deep") for i = 1, SAFE_CALL_DEPTH do root = json.util.buildCall("deep", root) end local encoded = json.encode(root) json.decode(encoded, { calls = { allowUndefined = true }}) end if os.getenv("TEST_UNSAFE") then local UNSAFE_DEPTH = 194 local UNSAFE_CALL_DEPTH = UNSAFE_DEPTH function test_object_unsafe_max_depth() local root = {} for i = 1, UNSAFE_DEPTH do root = { x = root } end local encoded = json.encode(root) json.decode(encoded) end function test_array_unsafe_max_depth() local root = {} for i = 1, UNSAFE_DEPTH do root = { root } end local encoded = json.encode(root) json.decode(encoded) end function test_function_unsafe_max_depth() local root = json.util.buildCall("deep") for i = 1, UNSAFE_CALL_DEPTH do root = json.util.buildCall("deep", root) end local encoded = json.encode(root) json.decode(encoded, { calls = { allowUndefined = true }}) end end lua-json-1.3.3/tests/lunit-encoderfunc.lua000066400000000000000000000016111256417601700205470ustar00rootroot00000000000000local json = require("json") local lunit = require("lunit") local math = require("math") local testutil = require("testutil") local setmetatable = setmetatable module("lunit-encoderfunc", lunit.testcase, package.seeall) local function build_call(name, parameters) return json.util.buildCall(name, unpack(parameters, parameters.n)) end function test_param_counts() local encoder = json.encode.getEncoder() assert(encoder(build_call('noparam', {}))) assert(encoder(build_call('oneparam', {1}))) assert(encoder(build_call('multiparam', {1,2}))) end function test_output() local encoder = json.encode.getEncoder() assert_equal('b64("hello")', encoder(build_call('b64', {'hello'}))) assert_equal('add(1,2)', encoder(build_call('add', {1,2}))) assert_equal('dood([b64("hello"),add(1,2)])', encoder(build_call('dood', { { build_call('b64', {'hello'}), build_call('add', {1,2}) } }))) end lua-json-1.3.3/tests/lunit-encoding.lua000066400000000000000000000025771256417601700200560ustar00rootroot00000000000000local json = require("json") local lunit = require("lunit") module("lunit-encoding", lunit.testcase, package.seeall) function test_cloned_array_sibling() local obj = {} assert_pass(function() json.encode({obj, obj}) end) end function test_cloned_object_sibling() local obj = {} assert_pass(function() json.encode({x = obj, y = obj}) end) end function test_cloned_array_deep_sibling() local obj = {} assert_pass(function() json.encode({ {obj}, {obj} }) end) end function test_cloned_array_multilevel_sibling() local obj = {} assert_pass(function() json.encode({ {obj, {obj}} }) end) end function test_recursive_object() local obj = {} obj.x = obj assert_error(function() json.encode(obj) end) end function test_recursive_array() local obj = {} obj[1] = obj assert_error(function() json.encode(obj) end) end function test_custom_encode() local obj = { x = "y" } local sawX local function preProcessor(value, isObjectKey) if value == "x" then sawX = true assert_true(isObjectKey) else assert_false(isObjectKey) end return value end local encoder = json.encode.getEncoder({ preProcess = preProcessor }) assert_nil(sawX) encoder(obj) assert_true(sawX) end function test_custom_array() assert_equal("[]", json.encode(setmetatable({}, {__is_luajson_array = true}))) assert_equal("[]", json.encode(json.util.InitArray({}))) end lua-json-1.3.3/tests/lunit-nothrow-decode.lua000066400000000000000000000010111256417601700211670ustar00rootroot00000000000000local json = require("json") local lunit = require("lunit") -- Test module for handling the simple decoding that behaves more like expected module("lunit-nothrow-decode", lunit.testcase, package.seeall) function test_decode_nothrow_bad_data() assert_nil((json.decode('x', {nothrow = true}))) assert_nil((json.decode('{x:x}', {nothrow = true}))) assert_nil((json.decode('[x:x]', {nothrow = true}))) assert_nil((json.decode('[1.fg]', {nothrow = true}))) assert_nil((json.decode('["\\xzz"]', {nothrow = true}))) end lua-json-1.3.3/tests/lunit-numbers.lua000066400000000000000000000073661256417601700177440ustar00rootroot00000000000000local json = require("json") local lunit = require("lunit") local math = require("math") local testutil = require("testutil") local string = require("string") local encode = json.encode -- DECODE NOT 'local' due to requirement for testutil to access it decode = json.decode.getDecoder(false) module("lunit-numbers", lunit.testcase, package.seeall) function setup() -- Ensure that the decoder is reset _G["decode"] = json.decode.getDecoder(false) end local function assert_near(expect, received) local pctDiff if expect == received then pctDiff = 0 else pctDiff = math.abs(1 - expect / received) end local msg = ("expected '%s' but was '%s' .. '%s'%% apart"):format(expect, received, pctDiff * 100) assert(pctDiff < 0.000001, msg) end local function test_simple(num) assert_near(num, decode(tostring(num))) end local function test_simple_w_encode(num) assert_near(num, decode(encode(num))) end local function test_scientific(num) assert_near(num, decode(string.format('%e', num))) assert_near(num, decode(string.format('%E', num))) end local numbers = { 0, 1, -1, math.pi, -math.pi } math.randomseed(0xDEADBEEF) -- Add sequence of numbers at low/high end of value-set for i = -300,300,60 do numbers[#numbers + 1] = math.random() * math.pow(10, i) numbers[#numbers + 1] = -math.random() * math.pow(10, i) end local function get_number_tester(f) return function () for _, v in ipairs(numbers) do f(v) end end end test_simple_numbers = get_number_tester(test_simple) test_simple_numbers_w_encode = get_number_tester(test_simple_w_encode) test_simple_numbers_scientific = get_number_tester(test_scientific) function test_infinite_nostrict() assert_equal(math.huge, decode("Infinity")) assert_equal(math.huge, decode("infinity")) assert_equal(-math.huge, decode("-Infinity")) assert_equal(-math.huge, decode("-infinity")) end function test_nan_nostrict() local value = decode("nan") assert_true(value ~= value) local value = decode("NaN") assert_true(value ~= value) end function test_expression() assert_error(function() decode("1 + 2") end) end -- For strict tests, small concession must be made to allow non-array/objects as root local strict = json.util.merge({}, json.decode.strict, {initialObject = false}) local strictDecoder = json.decode.getDecoder(strict) local numberValue = {hex = true} local hex = {number = numberValue} local hexDecoder = json.decode.getDecoder(hex) function test_hex() if decode == hexDecoder then -- MUST SKIP FAIL UNTIL BETTER METHOD SETUP return end assert_error(function() decode("0x20") end) end local hexNumbers = { 0xDEADBEEF, 0xCAFEBABE, 0x00000000, 0xFFFFFFFF, 0xCE, 0x01 } function test_hex_only() _G["decode"] = hexDecoder for _, v in ipairs(hexNumbers) do assert_equal(v, decode(("0x%x"):format(v))) assert_equal(v, decode(("0X%X"):format(v))) assert_equal(v, decode(("0x%X"):format(v))) assert_equal(v, decode(("0X%x"):format(v))) end end local decimal_hexes = { "0x0.1", "0x.1", "0x0e+1", "0x0E-1" } function test_no_decimal_hex_only() for _, str in ipairs(decimal_hexes) do assert_error(function() hexDecoder(str) end) end end function test_nearly_scientific_hex_only() assert_equal(0x00E1, hexDecoder("0x00e1")) end local function buildStrictDecoder(f) return testutil.buildPatchedDecoder(f, strictDecoder) end local function buildFailedStrictDecoder(f) return testutil.buildFailedPatchedDecoder(f, strictDecoder) end -- SETUP CHECKS FOR SEQUENCE OF DECODERS for k, v in pairs(_M) do if k:match("^test_") and not k:match("_gen$") and not k:match("_only$") then if k:match("_nostrict") then _M[k .. "_strict_gen"] = buildFailedStrictDecoder(v) else _M[k .. "_strict_gen"] = buildStrictDecoder(v) end _M[k .. "_hex_gen"] = testutil.buildPatchedDecoder(v, hexDecoder) end end lua-json-1.3.3/tests/lunit-simple-decode.lua000066400000000000000000000070501256417601700207710ustar00rootroot00000000000000local json = require("json") local lunit = require("lunit") -- Test module for handling the simple decoding that behaves more like expected module("lunit-simple-decode", lunit.testcase, package.seeall) function test_decode_simple_undefined() assert_nil(json.decode('undefined', json.decode.simple)) end function test_decode_default_undefined() assert_equal(json.util.undefined, json.decode('undefined')) end function test_decode_simple_null() assert_nil(json.decode('null', json.decode.simple)) end function test_decode_default_null() assert_equal(json.util.null, json.decode('null')) end function test_decode_array_simple_with_only_null() local result = assert(json.decode('[null]', json.decode.simple)) assert_nil(result[1]) assert_equal(1, result.n) end function test_decode_array_default_with_only_null() local result = assert(json.decode('[null]')) assert_equal(json.util.null, result[1]) assert_equal(1, #result) end function test_decode_array_simple_with_null() local result = assert(json.decode('[1, null, 3]', json.decode.simple)) assert_equal(1, result[1]) assert_nil(result[2]) assert_equal(3, result[3]) assert_equal(3, result.n) end function test_decode_array_default_with_null() local result = assert(json.decode('[1, null, 3]')) assert_equal(1, result[1]) assert_equal(json.util.null, result[2]) assert_equal(3, result[3]) assert_equal(3, #result) end function test_decode_small_array_simple_with_trailing_null() local result = assert(json.decode('[1, null]', json.decode.simple)) assert_equal(1, result[1]) assert_nil(result[2]) assert_equal(2, result.n) end function test_decode_small_array_default_with_trailing_null() local result = assert(json.decode('[1, null]')) assert_equal(1, result[1]) assert_equal(json.util.null, result[2]) assert_equal(2, #result) end function test_decode_small_array_simple_with_trailing_null() local result = assert(json.decode('[1, null]', json.decode.simple)) assert_equal(1, result[1]) assert_nil(result[2]) assert_equal(2, result.n) end function test_decode_small_array_default_with_trailing_null() local result = assert(json.decode('[1, null]')) assert_equal(1, result[1]) assert_equal(json.util.null, result[2]) assert_equal(2, #result) end function test_decode_array_simple_with_trailing_null() local result = assert(json.decode('[1, null, 3, null]', json.decode.simple)) assert_equal(1, result[1]) assert_nil(result[2]) assert_equal(3, result[3]) assert_nil(result[4]) assert_equal(4, result.n) end function test_decode_array_default_with_trailing_null() local result = assert(json.decode('[1, null, 3, null]')) assert_equal(1, result[1]) assert_equal(json.util.null, result[2]) assert_equal(3, result[3]) assert_equal(json.util.null, result[4]) assert_equal(4, #result) end function test_decode_object_simple_with_null() local result = assert(json.decode('{x: null}', json.decode.simple)) assert_nil(result.x) assert_nil(next(result)) end function test_decode_object_default_with_null() local result = assert(json.decode('{x: null}')) assert_equal(json.util.null, result.x) assert_not_nil(next(result)) end function test_decode_object_with_stringized_numeric_keys_default() local result = assert(json.decode('{"1": "one"}')) assert_equal("one", result["1"]) assert_equal(nil, result[1]) end function test_decode_object_with_stringized_numeric_keys_force_numeric() local result = assert( json.decode( '{"1": "one"}', { object = { setObjectKey = assert(json.decode.util.setObjectKeyForceNumber) } } ) ) assert_equal(nil, result["1"]) assert_equal("one", result[1]) end lua-json-1.3.3/tests/lunit-strings.lua000066400000000000000000000120431256417601700177460ustar00rootroot00000000000000local json = require("json") local lunit = require("lunit") local testutil = require("testutil") local string= require("string") local encode = json.encode -- DECODE NOT 'local' due to requirement for testutil to access it decode = json.decode.getDecoder(false) local error = error module("lunit-strings", lunit.testcase, package.seeall) local function assert_table_equal(expect, t) if type(expect) ~= 'table' then return assert_equal(expect, t) end for k,v in pairs(expect) do if type(k) ~= 'string' and type(k) ~= 'number' and type(k) ~= 'boolean' then error("INVALID expected table key") end local found = t[k] if found == nil then fail(tostring(k) .. " not found but expected") end assert_table_equal(v, t[k]) end for k,v in pairs(t) do if nil == expect[k] then fail(tostring(k) .. " found but not expected") end end end function setup() -- Ensure that the decoder is reset _G["decode"] = json.decode.getDecoder(false) end function test_strict_quotes() local opts = { strings = { strict_quotes = true } } assert_error(function() local decoder = json.decode.getDecoder(opts) decoder("'hello'") end) opts.strings.strict_quotes = false assert_equal("hello", json.decode.getDecoder(opts)("'hello'")) -- Quote test assert_equal("he'\"llo'", json.decode.getDecoder(opts)("'he\\'\"llo\\''")) end local utf16_matches = { -- 1-byte { '"\\u0000"', string.char(0x00) }, { '"\\u007F"', string.char(0x7F) }, -- 2-byte { '"\\u0080"', string.char(0xC2, 0x80) }, { '"\\u00A2"', string.char(0xC2, 0xA2) }, { '"\\u07FF"', string.char(0xDF, 0xBF) }, -- 3-byte { '"\\u0800"', string.char(0xE0, 0xA0, 0x80) }, { '"\\u20AC"', string.char(0xE2, 0x82, 0xAC) }, { '"\\uFEFF"', string.char(0xEF, 0xBB, 0xBF) }, { '"\\uFFFF"', string.char(0xEF, 0xBF, 0xBF) }, -- 4-byte - currently not handled --{ '"\\uD800\\uDC00"', string.char(0xF0, 0x90, 0x80, 0x80) }, --{ '"\\uDBFF\\uDFFF"', string.char(0xF4, 0x8F, 0xBF, 0xBF) } } function test_utf16_decode() for i, v in ipairs(utf16_matches) do -- Test that the default \u decoder outputs UTF8 local num = tostring(i) .. ' ' assert_equal(num .. v[2], num .. json.decode(v[1])) end end local BOM = string.char(0xEF, 0xBB, 0xBF) -- BOM skipping tests - here due to relation to UTF8/16 local BOM_skip_tests = { { BOM .. '"x"', "x" }, { BOM .. '["\\uFFFF",true]', { string.char(0xEF, 0xBF, 0xBF), true } }, -- Other uses of unicode spaces } function test_bom_skip() for i,v in ipairs(BOM_skip_tests) do assert_table_equal(v[2], json.decode(v[1])) end end -- Unicode whitespace codepoints gleaned from unicode.org local WHITESPACES = { "\\u0009", -- \t "\\u000A", -- \n "\\u000B", -- \v "\\u000C", -- \f "\\u000D", -- \r "\\u0020", -- space "\\u0085", "\\u00A0", "\\u1680", "\\u180E", "\\u2000", "\\u2001", "\\u2002", "\\u2003", "\\u2004", "\\u2005", "\\u2006", "\\u2007", "\\u2008", "\\u2009", "\\u200A", "\\u200B", -- addition, zero-width space "\\u2028", "\\u2029", "\\u202F", "\\u205F", "\\u3000", "\\uFEFF" -- Zero-width non-breaking space (BOM) } local inject_ws_values = { "%WS%true", " %WS%'the%WS blob' %WS%", "%WS%{ key: %WS%\"valueMan\",%WS% key2:%WS%4.4}", "%WS%false%WS%" } function test_whitespace_ignore() for _, ws in ipairs(WHITESPACES) do ws = json.decode('"' .. ws .. '"') for _, v in ipairs(inject_ws_values) do v = v:gsub("%%WS%%", ws) assert_true(nil ~= json.decode(v)) end end end function test_u_encoding() local encoder = json.encode.getEncoder() local decoder = json.decode.getDecoder() for i = 0, 255 do local char = string.char(i) assert_equal(char, decoder(encoder(char))) end end function test_x_encoding() local encoder = json.encode.getEncoder({ strings = { xEncode = true } }) local decoder = json.decode.getDecoder() for i = 0, 255 do local char = string.char(i) assert_equal(char, decoder(encoder(char))) end end local multibyte_encoding_values = { -- 2-byte { '"\\u0080"', string.char(0xC2, 0x80) }, { '"\\u00A2"', string.char(0xC2, 0xA2) }, { '"\\u07FF"', string.char(0xDF, 0xBF) }, -- 3-byte { '"\\u0800"', string.char(0xE0, 0xA0, 0x80) }, { '"\\u20AC"', string.char(0xE2, 0x82, 0xAC) }, { '"\\uFEFF"', string.char(0xEF, 0xBB, 0xBF) }, { '"\\uFFFF"', string.char(0xEF, 0xBF, 0xBF) }, -- 4-byte (surrogate pairs) { '"\\uD800\\uDC00"', string.char(0xF0, 0x90, 0x80, 0x80) }, { '"\\uDBFF\\uDFFF"', string.char(0xF4, 0x8F, 0xBF, 0xBF) } } function test_custom_encoding() local function processor(s) return require("utf8_processor").process(s) end local encoder = json.encode.getEncoder({ strings = { processor = processor } }) for i, v in ipairs(multibyte_encoding_values) do local encoded = encoder(v[2]) assert_equal(v[1], encoded, "Failed to encode value using custom encoder") end end function test_strict_decoding() local encoder = json.encode.getEncoder(json.encode.strict) local decoder = json.decode.getDecoder(json.decode.strict) for i = 0, 255 do local char = string.char(i) -- Must wrap character in array due to decoder strict-ness assert_equal(char, decoder(encoder({char}))[1]) end end lua-json-1.3.3/tests/lunit-tests.lua000066400000000000000000000027661256417601700174320ustar00rootroot00000000000000local json = require("json") local lunit = require("lunit") local testutil = require("testutil") -- DECODE NOT 'local' due to requirement for testutil to access it decode = json.decode.getDecoder(false) module("lunit-tests", lunit.testcase, package.seeall) function setup() _G["decode"] = json.decode.getDecoder(false) end function test_array_empty() local ret = assert_table(decode("[]")) assert_equal(0, #ret) assert_nil(next(ret)) end function test_array_trailComma_nostrict() local ret = assert_table(decode("[true,]")) assert_equal(true, ret[1]) assert_nil(next(ret, 1)) assert_equal(1, #ret) end function test_array_innerComma() assert_error(function() decode("[true,,true]") end) end function test_preprocess() assert_equal('"Hello"', json.encode(1, {preProcess = function() return "Hello" end})) assert_equal('-1', json.encode(1, {preProcess = function(x) return -x end})) assert_equal('-Infinity', json.encode(1/0, {preProcess = function(x) return -x end})) end local strictDecoder = json.decode.getDecoder(true) local function buildStrictDecoder(f) return testutil.buildPatchedDecoder(f, strictDecoder) end local function buildFailedStrictDecoder(f) return testutil.buildFailedPatchedDecoder(f, strictDecoder) end -- SETUP CHECKS FOR SEQUENCE OF DECODERS for k, v in pairs(_M) do if k:match("^test_") and not k:match("_gen$") then if k:match("_nostrict") then _M[k .. "_strict_gen"] = buildFailedStrictDecoder(v) else _M[k .. "_strict_gen"] = buildStrictDecoder(v) end end end lua-json-1.3.3/tests/regressionTest.lua000066400000000000000000000070511256417601700201470ustar00rootroot00000000000000-- Additional path that may be required local json = require("json") local io = require("io") local os = require("os") local lfs = require("lfs") local success = true local function getFileData(fileName) local f = io.open(fileName, 'rb') if not f then return end local data = f:read('*a') f:close() return data end local function putTempData(data) local name = os.tmpname() local f = assert(io.open(name, 'wb')) f:write(data) f:close() return name end -- Ensure that the encoder/decoder can round-trip valid JSON local function RoundTripTest(parseFunc, encodeFunc, jsonData, luaData, fullRoundTrip, failRoundTrip) local success, dataString = pcall(encodeFunc, luaData) if failRoundTrip then assert(not success, "Round trip encoding test result not as expected") return true else assert(success, "Couldn't encode the lua data..." .. tostring(dataString)) end local success, result = pcall(parseFunc, dataString) if not success then print("Could not parse the generated JSON of (", luaData) print("GENERATED: [[" .. dataString .. "]]") print("DATA STORED IN: ", putTempData(dataString)) return end if fullRoundTrip then -- Ensure that whitespace is trimmed off ends dataString = dataString:match("^[%s]*(.-)[%s]*$") jsonData = jsonData:match("^[%s]*(.-)[%s]*$") if dataString ~= jsonData then print("Encoded values do not match") print("ORIGINAL: << " .. jsonData .. " >>") print("RE-ENCOD: << " .. dataString .. " >>") return end end return true end local function testFile(fileName, parseFunc, encodeFunc, expectSuccess, fullRoundTrip, failRoundTrip) local data = getFileData(fileName) if not data then return end io.write(".") local succeed, result = pcall(parseFunc, data) if expectSuccess ~= succeed then print("Wrongly " .. (expectSuccess and "Failed" or "Succeeded") .. " on : " .. fileName .. "(" .. tostring(result) .. ")") success = false elseif succeed then if not RoundTripTest(parseFunc, encodeFunc, data, result, fullRoundTrip, failRoundTrip) then print("FAILED TO ROUND TRIP: " .. fileName) success = false end end end local function testDirectories(parseFunc, encodeFunc, directories, ...) if not directories then return end for _,directory in ipairs(directories) do if lfs.attributes(directory, 'mode') == 'directory' then for f in lfs.dir(directory) do testFile(directory .. "/" .. f, parseFunc, encodeFunc, ...) end end end io.write("\n") end local function TestParser(parseFunc, encodeFunc, successNames, failNames, roundTripNames) testDirectories(parseFunc, encodeFunc, successNames, true, false) testDirectories(parseFunc, encodeFunc, failNames, false, false) testDirectories(parseFunc, encodeFunc, roundTripNames, true, true) end print("Testing lax/fast mode:") TestParser(json.decode.getDecoder(), json.encode.getEncoder(), {"test/pass","test/fail_strict"}, {"test/fail_all"},{"test/roundtrip","test/roundtrip_lax"}) print("Testing (mostly) strict mode:") local strict = json.util.merge({}, json.decode.strict, { number = { nan = false, inf = true, strict = true } }) local strict_encode = json.util.merge({}, json.encode.strict, { number = { nan = false, inf = true, strict = true } }) TestParser(json.decode.getDecoder(strict), json.encode.getEncoder(strict_encode), {"test/pass"}, {"test/fail_strict","test/fail_all"}, {"test/roundtrip"}) print("Testing (mostly) strict encoder with non-strict decodings") testDirectories(json.decode.getDecoder(), json.encode.getEncoder(json.encode.strict), {"test/fail_strict_encode"}, true, true, true) if not success then os.exit(1) end lua-json-1.3.3/tests/test.lua000066400000000000000000000043661256417601700161140ustar00rootroot00000000000000-- Additional path that may be required require("json") local testStrings = { [[{1:[1213.3e12, 123 , 123, "hello", [12, 2], {1:true /*test*/}]}]], [[{"username":"demo1","message":null,"password":""}]], [[{"challenge":"b64d-fnNQ6bRZ7CYiNIKwmdHoNgl9JR9MIYtzjBhpQzYXCFrgARt9mNmgUuO7FoODGr1NieT9yTeB2SLztGkvIA4NXmN9Bi27hqx1ybJIQq6S2L-AjQ3VTDClSmCsYFPOm9EMVZDZ0jhBX1fXw3o9VYj1j9KzSY5VCSAzGqYo-cBPY\n.b64","cert":"b64MIIGyjCCBbKgAwIBAgIKFAC1ZgAAAAAUYzANBgkqhkiG9w0BAQUFADBZMRUwEwYKCZImiZPyLGQBGRYFbG9tp8uQuFjWGS_KxTHXz9vkLNFjOoZY2bOwzsdEpshuYSdvX-9bRvHTQcoMNz8Q9nXG1aMl5x1nbV5byQNTCJlz4gzMJeNfeKGcipdCj7B6e_VpF-n2P-dFZizUHjxMksCVZ3nTr51x3Uw\n.b64","key":"D79B30BA7954DF520B44897A6FF58919"}]], [[{"key":"D79B30BA7954DF520B44897A6FF58919"}]], [[{"val":undefined}]], [[{ "Image": { "Width": 800, "Height": 600, "Title": "View from 15th Floor", "Thumbnail": { "Url": "http://www.example.com/image/481989943", "Height": 125, "Width": "100" }, "IDs": [116, 943, 234, 38793] } }]], [[ [ { "precision": "zip", "Latitude": 37.7668, "Longitude": -122.3959, "Address": "", "City": "SAN FRANCISCO", "State": "CA", "Zip": "94107", "Country": "US" }, { "precision": "zip", "Latitude": 37.371991, "Longitude": -122.026020, "Address": "", "City": "SUNNYVALE", "State": "CA", "Zip": "94085", "Country": "US" } ] ]], [[[null,true,[1,2,3],"hello\"],[world!"] ]], [[ [{"0":"tan\\\\","model\\\\":"sedan"},{"0":"red","model":"sports"}] ]], [[ {"1":"one","2":"two","5":"five"} ]], [=[ [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] ]=] } for i, v in ipairs(testStrings) do print("Testing: #" .. i) local dec = json.decode(v) json.util.printValue(dec, "JSONVALUE") local reenc = json.encode(dec) print("RE_ENC: ", reenc) local redec = json.decode(reenc) json.util.printValue(redec, "REDECJSONVALUE") end local testValues = { {[300] = {nil, true, 1,2,3, nil, 3}} } for _, v in ipairs(testValues) do local ret = json.encode(v) print(ret) local dec = json.decode(ret) json.util.printValue(dec, "Encoded value") print("Re-encoded", json.encode(dec)) end lua-json-1.3.3/tests/test/000077500000000000000000000000001256417601700154005ustar00rootroot00000000000000lua-json-1.3.3/tests/test/fail_all/000077500000000000000000000000001256417601700171435ustar00rootroot00000000000000lua-json-1.3.3/tests/test/fail_all/colonInArray.json000066400000000000000000000000411256417601700224310ustar00rootroot00000000000000["Colon instead of comma": false]lua-json-1.3.3/tests/test/fail_all/commaAfterValue.json000066400000000000000000000000321256417601700231040ustar00rootroot00000000000000["Comma after the close"],lua-json-1.3.3/tests/test/fail_all/doubleColon.json000066400000000000000000000000271256417601700223020ustar00rootroot00000000000000{"Double colon":: null}lua-json-1.3.3/tests/test/fail_all/extraArrayClose.json000066400000000000000000000000201256417601700231360ustar00rootroot00000000000000["Extra close"]]lua-json-1.3.3/tests/test/fail_all/extraValueAfterClose.json000066400000000000000000000000721256417601700241250ustar00rootroot00000000000000{"Extra value after close": true} "misplaced quoted value"lua-json-1.3.3/tests/test/fail_all/functionExpression.json000066400000000000000000000000371256417601700237430ustar00rootroot00000000000000{"Illegal invocation": alert()}lua-json-1.3.3/tests/test/fail_all/hexNumber.json000066400000000000000000000000371256417601700217730ustar00rootroot00000000000000{"Numbers cannot be hex": 0x14}lua-json-1.3.3/tests/test/fail_all/lineBreakInString-escaped.json000066400000000000000000000000171256417601700250100ustar00rootroot00000000000000["line\ break"]lua-json-1.3.3/tests/test/fail_all/mathExpression.json000066400000000000000000000000351256417601700230450ustar00rootroot00000000000000{"Illegal expression": 1 + 2}lua-json-1.3.3/tests/test/fail_all/missingArrayValue.json000066400000000000000000000000321256417601700234760ustar00rootroot00000000000000[ , "<-- missing value"]lua-json-1.3.3/tests/test/fail_all/missingColon.json000066400000000000000000000000261256417601700225000ustar00rootroot00000000000000{"Missing colon" null}lua-json-1.3.3/tests/test/fail_all/missingColon2.json000066400000000000000000000000401256417601700225560ustar00rootroot00000000000000{"Comma instead of colon", null}lua-json-1.3.3/tests/test/fail_all/octalEscape.json000066400000000000000000000000421256417601700222550ustar00rootroot00000000000000["Illegal backslash escape: \017"]lua-json-1.3.3/tests/test/fail_all/octalNumber.json000066400000000000000000000000531256417601700223070ustar00rootroot00000000000000{"Numbers cannot have leading zeroes": 013}lua-json-1.3.3/tests/test/fail_all/tabInString-escaped.json000066400000000000000000000000461256417601700236640ustar00rootroot00000000000000["tab\ character\ in\ string\ "]lua-json-1.3.3/tests/test/fail_all/trailingDoubleComma.json000066400000000000000000000000301256417601700237500ustar00rootroot00000000000000["double extra comma",,]lua-json-1.3.3/tests/test/fail_all/unclosed_array.json000066400000000000000000000000211256417601700230410ustar00rootroot00000000000000["Unclosed array"lua-json-1.3.3/tests/test/fail_all/unknownLiteral.json000066400000000000000000000000241256417601700230460ustar00rootroot00000000000000["Bad value", truth]lua-json-1.3.3/tests/test/fail_strict/000077500000000000000000000000001256417601700177035ustar00rootroot00000000000000lua-json-1.3.3/tests/test/fail_strict/hexEscape.json000066400000000000000000000000421256417601700224770ustar00rootroot00000000000000["Illegal backslash escape: \x15"]lua-json-1.3.3/tests/test/fail_strict/lineBreakInString.json000066400000000000000000000000161256417601700241450ustar00rootroot00000000000000["line break"]lua-json-1.3.3/tests/test/fail_strict/mustBeArrayOrObject.json000066400000000000000000000000741256417601700244650ustar00rootroot00000000000000"A JSON payload should be an object or array, not a string."lua-json-1.3.3/tests/test/fail_strict/singleQuoteEscape.json000066400000000000000000000000401256417601700242100ustar00rootroot00000000000000["Illegal backslash escape: \'"]lua-json-1.3.3/tests/test/fail_strict/singleQuotes.json000066400000000000000000000000201256417601700232500ustar00rootroot00000000000000['single quote']lua-json-1.3.3/tests/test/fail_strict/tabInString.json000066400000000000000000000000441256417601700230200ustar00rootroot00000000000000["tab character in string "] lua-json-1.3.3/tests/test/fail_strict/trailingArrayComma.json000066400000000000000000000000201256417601700243530ustar00rootroot00000000000000["extra comma",]lua-json-1.3.3/tests/test/fail_strict/trailingObjectComma.json000066400000000000000000000000261256417601700245110ustar00rootroot00000000000000{"Extra comma": true,}lua-json-1.3.3/tests/test/fail_strict/unquotedKey.json000066400000000000000000000000451256417601700231120ustar00rootroot00000000000000{unquoted_key: "keys must be quoted"}lua-json-1.3.3/tests/test/fail_strict/whitespace_before_value.json000066400000000000000000000000161256417601700254450ustar00rootroot00000000000000 "test string"lua-json-1.3.3/tests/test/fail_strict_encode/000077500000000000000000000000001256417601700212205ustar00rootroot00000000000000lua-json-1.3.3/tests/test/fail_strict_encode/bool.json000066400000000000000000000000051256417601700230410ustar00rootroot00000000000000true lua-json-1.3.3/tests/test/fail_strict_encode/inf.json000066400000000000000000000000161256417601700226640ustar00rootroot00000000000000{x: Infinity} lua-json-1.3.3/tests/test/fail_strict_encode/nan.json000066400000000000000000000000111256417601700226570ustar00rootroot00000000000000{x: NaN} lua-json-1.3.3/tests/test/fail_strict_encode/null.json000066400000000000000000000000051256417601700230600ustar00rootroot00000000000000null lua-json-1.3.3/tests/test/fail_strict_encode/number.json000066400000000000000000000000041256417601700233750ustar00rootroot00000000000000100 lua-json-1.3.3/tests/test/fail_strict_encode/string.json000066400000000000000000000000161256417601700234160ustar00rootroot00000000000000"Heloo world" lua-json-1.3.3/tests/test/fail_strict_encode/undefined.json000066400000000000000000000000171256417601700240520ustar00rootroot00000000000000{x: undefined} lua-json-1.3.3/tests/test/pass/000077500000000000000000000000001256417601700163465ustar00rootroot00000000000000lua-json-1.3.3/tests/test/pass/extremeNesting.json000066400000000000000000000000621256417601700222400ustar00rootroot00000000000000[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]lua-json-1.3.3/tests/test/pass/pass1.json000066400000000000000000000025531256417601700202750ustar00rootroot00000000000000[ "JSON Test Pattern pass1", {"object with 1 member":["array with 1 element"]}, {}, [], -42, true, false, null, { "integer": 1234567890, "real": -9876.543210, "e": 0.123456789e-12, "E": 1.234567890E+34, "": 23456789012E666, "zero": 0, "one": 1, "space": " ", "quote": "\"", "backslash": "\\", "controls": "\b\f\n\r\t", "slash": "/ & \/", "alpha": "abcdefghijklmnopqrstuvwyz", "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", "digit": "0123456789", "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", "true": true, "false": false, "null": null, "array":[ ], "object":{ }, "address": "50 St. James Street", "url": "http://www.JSON.org/", "comment": "// /* */": " ", " s p a c e d " :[1,2 , 3 , 4 , 5 , 6 ,7 ], "compact": [1,2,3,4,5,6,7], "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", "quotes": "" \u0022 %22 0x22 034 "", "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" : "A key can be any string" }, 0.5 ,98.6 , 99.44 , 1066 ,"rosebud"]lua-json-1.3.3/tests/test/pass/pass3.json000066400000000000000000000002241256417601700202700ustar00rootroot00000000000000{ "JSON Test Pattern pass3": { "The outermost value": "must be an object or array.", "In this test": "It is an object." } } lua-json-1.3.3/tests/test/pass/stringWithEscapedAndUnescapedSlash.json000066400000000000000000000000131256417601700261300ustar00rootroot00000000000000["/ & \/"] lua-json-1.3.3/tests/test/pass/whitespace_before_array.json000066400000000000000000000000061256417601700241110ustar00rootroot00000000000000 [1,2]lua-json-1.3.3/tests/test/pass/whitespace_before_object.json000066400000000000000000000000411256417601700242400ustar00rootroot00000000000000 {"a":"Whitespace before object"}lua-json-1.3.3/tests/test/roundtrip/000077500000000000000000000000001256417601700174265ustar00rootroot00000000000000lua-json-1.3.3/tests/test/roundtrip/deepArray.json000066400000000000000000000000641256417601700222350ustar00rootroot00000000000000[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]lua-json-1.3.3/tests/test/roundtrip/emptyArray.json000066400000000000000000000000031256417601700224470ustar00rootroot00000000000000[] lua-json-1.3.3/tests/test/roundtrip/emptyObject.json000066400000000000000000000000031256417601700225770ustar00rootroot00000000000000{} lua-json-1.3.3/tests/test/roundtrip/simpleArrayInObject.json000066400000000000000000000000621256417601700242250ustar00rootroot00000000000000{"object with 1 member":["array with 1 element"]} lua-json-1.3.3/tests/testutil.lua000066400000000000000000000006771256417601700170130ustar00rootroot00000000000000local pcall, error = pcall, error local lunit = require("lunit") local assert_error = lunit.assert_error -- Allow module to alter decoder local function setDecoder(d) _G.decode = d end module("testutil", package.seeall) function buildPatchedDecoder(f, newDecoder) return function() setDecoder(newDecoder) f() end end function buildFailedPatchedDecoder(f, newDecoder) return function() setDecoder(newDecoder) assert_error(f) end end lua-json-1.3.3/tests/timetrials.lua000066400000000000000000000021571256417601700173060ustar00rootroot00000000000000--[[ Some Time Trails for the JSON4Lua package ]]-- require('json') local os = require('os') local table = require('table') local string = require("string") local skipDecode = (...) == '--skipDecode' local count = tonumber(select(2, ...) or 500) or 500 local strDup = tonumber(select(3, ...) or 1) or 1 local t1 = os.clock() local jstr local v for i=1,count do local t = {} for j=1,500 do t[#t + 1] = j end for j=1,500 do t[#t + 1] = string.rep("VALUE", strDup) end jstr = json.encode(t) if not skipDecode then v = json.decode(jstr) end --print(json.encode(t)) end for i = 1,count do local t = {} for j=1,500 do local m= j % 4 local idx = string.rep('a'..j, strDup) if (m==0) then t[idx] = true elseif m==1 then t[idx] = json.util.null elseif m==2 then t[idx] = j else t[idx] = string.char(j % 0xFF) end end jstr = json.encode(t) if not skipDecode then v = json.decode(jstr) end end print (jstr) --print(type(t1)) local t2 = os.clock() print ("Elapsed time=" .. os.difftime(t2,t1) .. "s") lua-json-1.3.3/tests/utf8_processor.lua000066400000000000000000000024141256417601700201120ustar00rootroot00000000000000local lpeg = require("lpeg") local string = string module("utf8_processor") local function encode_utf(codepoint) if codepoint > 0x10FFFF then error("Codepoint > 10FFFF cannot be encoded") elseif codepoint > 0xFFFF then -- Surrogate pair needed codepoint = codepoint - 0x10000 local first, second = codepoint / 0x0400 + 0xD800, codepoint % 0x0400 + 0xDC00 return ("\\u%.4X\\u%.4X"):format(first, second) else return ("\\u%.4X"):format(codepoint) end end -- decode a two-byte UTF-8 sequence local function f2 (s) local c1, c2 = string.byte(s, 1, 2) return encode_utf(c1 * 64 + c2 - 12416) end -- decode a three-byte UTF-8 sequence local function f3 (s) local c1, c2, c3 = string.byte(s, 1, 3) return encode_utf((c1 * 64 + c2) * 64 + c3 - 925824) end -- decode a four-byte UTF-8 sequence local function f4 (s) local c1, c2, c3, c4 = string.byte(s, 1, 4) return encode_utf(((c1 * 64 + c2) * 64 + c3) * 64 + c4 - 63447168) end local cont = lpeg.R("\128\191") -- continuation byte local utf8 = lpeg.R("\0\127") -- Do nothing here + lpeg.R("\194\223") * cont / f2 + lpeg.R("\224\239") * cont * cont / f3 + lpeg.R("\240\244") * cont * cont * cont / f4 local utf8_decode_pattern = lpeg.Cs(utf8^0) * -1 function process(s) return utf8_decode_pattern:match(s) end lua-json-1.3.3/util/000077500000000000000000000000001256417601700142345ustar00rootroot00000000000000lua-json-1.3.3/util/createRock.lua000066400000000000000000000022111256417601700170150ustar00rootroot00000000000000local io = require("io") local version = assert((...), "Requires rock version on command-line") local template = [=[ package = "luajson" version = %VERSION% source = { url = "git://github.com/harningt/luajson.git", tag = %TAG_VERSION% } description = { summary = "customizable JSON decoder/encoder", detailed = [[ LuaJSON is a customizable JSON decoder/encoder using LPEG for parsing. ]], homepage = "http://github.com/harningt/luajson", maintainer = "Thomas Harning ", license = "MIT/X11" } dependencies = { "lua >= 5.1", "lpeg >= 0.8.1" } build = { type = "module", modules = { %MODULES% } } ]=] local in_modules = io.popen("find lua -type f -name '*.lua' -not -iname '.*' | sort", "r") local modules = in_modules:read("*a") in_modules:close() modules = modules:gsub("lua/([^\n]*)%.lua", function(module) return "\t\t[" .. ("%q"):format(module:gsub("/",".")) .. "] = " .. ("%q"):format("lua/" .. module .. ".lua") .. "," end) tag_version = version:match("^(.*)[-]") local out = template:gsub("%%(.-)%%", { VERSION = ("%q"):format(version), TAG_VERSION = ("%q"):format(tag_version), MODULES = modules }) print(out) lua-json-1.3.3/util/prepareNextRelease.lua000077500000000000000000000013301256417601700205350ustar00rootroot00000000000000#!/usr/bin/env lua local io = require("io") local from, tover = ... if not from or not tover then print("Format: prepareNextRelease.lua ") return end local f = assert(io.open("docs/ReleaseNotes-" .. tover .. ".txt", "w")) local headLine = "luajson v" .. tover .. " Release Notes" f:write(headLine, "\n", ("="):rep(#headLine), "\n\n") f:write([[ User Visible Changes -------------------- Plans for next release ---------------------- ]]) local tailLine = "Updates since " .. from f:write(tailLine, "\n", ("="):rep(#tailLine), "\n\n") local data = assert(io.popen("git shortlog " .. from .. "..HEAD | util/processShortlog.lua", "r")) local tail = data:read("*a") data:close() f:write(tail) f:close() lua-json-1.3.3/util/processShortlog.lua000077500000000000000000000021401256417601700201370ustar00rootroot00000000000000#!/usr/bin/env lua local io = require("io") local table = require("table") local authors = {} local currentAuthor local function pushValue(t, group, value) local items = t[group] or {} t[group] = items items[#items + 1] = value end for line in io.lines() do local author = line:match("^(.- %(%d*%):)$") line = line:match("^%s*(.-)%s*$") if author then currentAuthor = authors[author] or {} authors[author] = currentAuthor elseif currentAuthor and #line > 0 then local msg = line:gsub("^%s*","") local group, data = msg:match("^([^:]*[%s]*:)[%s]*(.*)$") if not group then pushValue(currentAuthor, "-ungrouped-", msg) else pushValue(currentAuthor, group, data) end end end for author, groups in pairs(authors) do print(author) -- SORT GROUPS local sorted = {} for group, groupValues in pairs(groups) do sorted[#sorted + 1] = {group, groupValues} end table.sort(sorted, function(a,b) return a[1] < b[1] end) for _, gv in ipairs(sorted) do local group, groupValues = unpack(gv) print("\t" .. group) for _, entry in ipairs(groupValues) do print("\t\t" .. entry) end end end