jbe@255: --[[-- jbe@255: request.add_variable( jbe@255: tbl, -- table where the variable is stored jbe@255: key, -- name of variable (key within the table) jbe@255: value -- optional value for initialization jbe@255: ) jbe@255: jbe@259: 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. jbe@255: jbe@255: --]]-- jbe@255: jbe@255: function request.add_variable(tbl, key, value) jbe@259: local initval, istable jbe@255: tbl[key] = value jbe@255: request.add_initializer(function(first) jbe@255: if first then jbe@259: initval = tbl[key] jbe@259: istable = type(initval) == "table" jbe@255: else jbe@259: if istable then jbe@259: tbl[key] = table.new(initval) jbe@259: else jbe@259: tbl[key] = initval jbe@259: end jbe@255: end jbe@255: end) jbe@255: end