webmcp

diff framework/env/slot/dump_all.lua @ 0:9fdfb27f8e67

Version 1.0.0
author jbe/bsw
date Sun Oct 25 12:00:00 2009 +0100 (2009-10-25)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/slot/dump_all.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,36 @@
     1.4 +--[[--
     1.5 +blob =           -- string for later usage with slot.restore_all(...)
     1.6 +slot.dump_all()
     1.7 +
     1.8 +Returns a single string, containing all slot contents. The result of this function can be used to restore all slots after a 303 redirect. This is done automatically by the WebMCP using slot.restore_all(...). If the result of this function is an empty string, then all slots are empty.
     1.9 +
    1.10 +--]]--
    1.11 +
    1.12 +local function encode(str)
    1.13 +  return (
    1.14 +    string.gsub(
    1.15 +      str,
    1.16 +      "[=;%[%]]",
    1.17 +      function(char)
    1.18 +        if char == "=" then return "[eq]"
    1.19 +        elseif char == ";" then return "[s]"
    1.20 +        elseif char == "[" then return "[o]"
    1.21 +        elseif char == "]" then return "[c]"
    1.22 +        else end
    1.23 +      end
    1.24 +    )
    1.25 +  )
    1.26 +end
    1.27 +
    1.28 +function slot.dump_all()
    1.29 +  local blob_parts = {}
    1.30 +  for key in pairs(slot._data) do
    1.31 +    if type(key) == "string" then
    1.32 +      local value = slot.get_content(key)
    1.33 +      if value ~= "" then
    1.34 +        blob_parts[#blob_parts + 1] = encode(key) .. "=" .. encode(value)
    1.35 +      end
    1.36 +    end
    1.37 +  end
    1.38 +  return table.concat(blob_parts, ";")
    1.39 +end

Impressum / About Us