diff options
Diffstat (limited to 'aconf/util.lua')
-rw-r--r-- | aconf/util.lua | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/aconf/util.lua b/aconf/util.lua index d5d5d42..373fc29 100644 --- a/aconf/util.lua +++ b/aconf/util.lua @@ -3,7 +3,7 @@ -- @module aconf.util --[[ -Copyright (c) 2012-2014 Kaarle Ritvanen +Copyright (c) 2012-2015 Kaarle Ritvanen See LICENSE file for license details --]] @@ -22,13 +22,14 @@ end --- merge a table into another. -- Copy values for all keys from `src` to `dst` and optionally keep existing --- values. +-- values. A new table is created if `dst` is nil. -- @param dst the destination table -- @param src the source table -- @param preserve a boolean. If true then will existing entries in `dst` be -- kept. -- @return the destination table, `dst` function M.update(dst, src, preserve) + if not dst then dst = {} end for k, v in pairs(src) do if not preserve or dst[k] == nil then dst[k] = v end end @@ -37,7 +38,7 @@ end --- copy default vaules from one table to another. -- Copy all entries in `src` to `dst` but keep any already existing values --- in `dst`. +-- in `dst`. A new table is created if `dst` is nil. -- @param dst the destination table -- @param src the source table containing the default values -- @return the destination table, `dst` |