webmcp

diff framework/env/slot/restore_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/restore_all.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,32 @@
     1.4 +--[[--
     1.5 +slot.restore_all(
     1.6 +  blob             -- string as returned by slot.dump_all()
     1.7 +)
     1.8 +
     1.9 +Restores all slots using a string created by slot.dump_all().
    1.10 +
    1.11 +--]]--
    1.12 +
    1.13 +local function decode(str)
    1.14 +  return (
    1.15 +    string.gsub(
    1.16 +      str,
    1.17 +      "%[[a-z]+%]",
    1.18 +      function(char)
    1.19 +        if char == "[eq]" then return "="
    1.20 +        elseif char == "[s]" then return ";"
    1.21 +        elseif char == "[o]" then return "["
    1.22 +        elseif char == "[c]" then return "]"
    1.23 +        else end
    1.24 +      end
    1.25 +    )
    1.26 +  )
    1.27 +end
    1.28 +
    1.29 +function slot.restore_all(blob)
    1.30 +  slot.reset_all()
    1.31 +  for encoded_key, encoded_value in string.gmatch(blob, "([^=;]*)=([^=;]*)") do
    1.32 +    local key, value = decode(encoded_key), decode(encoded_value)
    1.33 +    slot._data[key].string_fragments = { value }
    1.34 +  end
    1.35 +end

Impressum / About Us