webmcp
annotate framework/env/slot/reset_all.lua @ 288:c51f283dfb0d
Request/response timeouts
author | jbe |
---|---|
date | Sun Mar 22 12:21:46 2015 +0100 (2015-03-22) |
parents | f491011ebe16 |
children |
rev | line source |
---|---|
jbe/bsw@0 | 1 --[[-- |
poelzi@34 | 2 slot.reset_all{ |
jbe@47 | 3 except = except -- Reset all slots, except slots named in this list |
poelzi@34 | 4 } |
jbe/bsw@0 | 5 |
jbe@47 | 6 Calling this function resets all slots to be empty. An exclusion list may be passed to the function as named argument. |
jbe/bsw@0 | 7 |
jbe/bsw@0 | 8 --]]-- |
jbe/bsw@0 | 9 |
jbe@260 | 10 local data_metatable = {} |
jbe@260 | 11 function data_metatable:__index(key) |
jbe@260 | 12 self[key] = { string_fragments = {}, state_table = {} } |
jbe@260 | 13 return self[key] |
jbe@260 | 14 end |
jbe@260 | 15 |
poelzi@34 | 16 function slot.reset_all(args) |
jbe@257 | 17 local saved |
poelzi@34 | 18 if args and args.except then |
jbe@257 | 19 saved = {} |
jbe@47 | 20 for i, key in ipairs(args.except) do |
poelzi@34 | 21 saved[key] = slot._data[key] |
poelzi@34 | 22 end |
poelzi@34 | 23 end |
jbe@260 | 24 slot._data = setmetatable({}, data_metatable) |
poelzi@34 | 25 if saved then |
jbe@47 | 26 for key, value in pairs(saved) do |
poelzi@34 | 27 slot._data[key] = value |
poelzi@34 | 28 end |
poelzi@34 | 29 end |
jbe/bsw@0 | 30 end |