# HG changeset patch # User jbe # Date 1426378461 -3600 # Node ID 41be09ce6aa3faf8ebf2d47331c3d0cd591f4042 # Parent 46f0083889a95cc66a0702733710177cc665fe2f Allow tables as sub-values of request variables (won't be cloned) diff -r 46f0083889a9 -r 41be09ce6aa3 framework/env/request/add_variable.lua --- a/framework/env/request/add_variable.lua Sun Mar 15 01:08:00 2015 +0100 +++ b/framework/env/request/add_variable.lua Sun Mar 15 01:14:21 2015 +0100 @@ -5,18 +5,23 @@ value -- optional value for initialization ) -Marks a field of a table to be re-initialized for every request. If this variable (i.e. the field of the table) is modified before the first requst is being handled (e.g. during configuration or pre-/post-fork initializers), then the modified value will be used for re-initialization on every request. See env/request/__init.lua for an example. +Marks a field of a table to be re-initialized for every request. If this variable (i.e. the field of the table) is modified before the first requst is being handled (e.g. during configuration or pre-/post-fork initializers), then the modified value will be used for re-initialization on every request. If the (modified) value is a table, the table will be cloned on every request to avoid side-effects between different requests. Note, however, that only the first level of the table is cloned. See env/request/__init.lua for examples. --]]-- function request.add_variable(tbl, key, value) - local initialized_value + local initval, istable tbl[key] = value request.add_initializer(function(first) if first then - initialized_value = tbl[key] + initval = tbl[key] + istable = type(initval) == "table" else - tbl[key] = initialized_value + if istable then + tbl[key] = table.new(initval) + else + tbl[key] = initval + end end end) end