From 3883db4b5f24cb685af7998dbe38e18ca7ff54ff Mon Sep 17 00:00:00 2001 From: Thomas Harning Jr Date: Sun, 10 Mar 2013 20:47:05 -0400 Subject: [PATCH] docs: adds merge behavior documentation --- README | 3 +++ lua/json/util.lua | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/README b/README index d23facd..9a38173 100644 --- a/README +++ b/README @@ -58,6 +58,9 @@ Module/Function overview: --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/ diff --git a/lua/json/util.lua b/lua/json/util.lua index 6ceb759..d7d5d25 100644 --- a/lua/json/util.lua +++ b/lua/json/util.lua @@ -59,6 +59,14 @@ local function inner_merge(t, remaining, from, ...) 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 -- 2.11.4.GIT