diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2015-01-23 21:02:03 +0200 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2015-01-23 23:31:43 +0200 |
commit | 6821eddbd05f92957b87c6dc775e229841af8e11 (patch) | |
tree | f108deae25a3a67fcbfa9e4c54a239515b860d5a | |
parent | 9c41b91f0fdefbbf2f16a19c52ef9dbd06cc2bcf (diff) | |
download | aconf-6821eddbd05f92957b87c6dc775e229841af8e11.tar.bz2 aconf-6821eddbd05f92957b87c6dc775e229841af8e11.tar.xz |
util: update: create a new table if destination is nil
-rw-r--r-- | aconf/model/set.lua | 4 | ||||
-rw-r--r-- | aconf/util.lua | 7 | ||||
-rw-r--r-- | server.lua | 5 |
3 files changed, 8 insertions, 8 deletions
diff --git a/aconf/model/set.lua b/aconf/model/set.lua index 8b51f12..897e1bf 100644 --- a/aconf/model/set.lua +++ b/aconf/model/set.lua @@ -1,5 +1,5 @@ --[[ -Copyright (c) 2012-2014 Kaarle Ritvanen +Copyright (c) 2012-2015 Kaarle Ritvanen See LICENSE file for license details --]] @@ -35,7 +35,7 @@ function M.Set:init(context, params) local mt = getmetatable(self) function mt.get(k, options) - options = util.setdefaults(options or {}, {dereference=true}) + options = util.setdefaults(options, {dereference=true}) local i, v = find(k) if i then return mt.load(i, options) end if options.create then return v end 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` @@ -1,5 +1,5 @@ --[[ -Copyright (c) 2012-2014 Kaarle Ritvanen +Copyright (c) 2012-2015 Kaarle Ritvanen See LICENSE file for license details --]] @@ -24,8 +24,7 @@ local sessions = {} return function(env) local function wrap(code, headers, res, encode) - if not headers then headers = {} end - update( + headers = update( headers, { ['Cache-Control']='no-cache, no-store, must-revalidate', |