webmcp
annotate framework/env/slot/restore_all.lua @ 398:ac9a4e1885da
Dropped compatibility code for Lua 5.1 (assume LUA_VERSION_NUM >= 502)
author | jbe |
---|---|
date | Thu Dec 10 17:27:53 2015 +0100 (2015-12-10) |
parents | 9fdfb27f8e67 |
children |
rev | line source |
---|---|
jbe/bsw@0 | 1 --[[-- |
jbe/bsw@0 | 2 slot.restore_all( |
jbe/bsw@0 | 3 blob -- string as returned by slot.dump_all() |
jbe/bsw@0 | 4 ) |
jbe/bsw@0 | 5 |
jbe/bsw@0 | 6 Restores all slots using a string created by slot.dump_all(). |
jbe/bsw@0 | 7 |
jbe/bsw@0 | 8 --]]-- |
jbe/bsw@0 | 9 |
jbe/bsw@0 | 10 local function decode(str) |
jbe/bsw@0 | 11 return ( |
jbe/bsw@0 | 12 string.gsub( |
jbe/bsw@0 | 13 str, |
jbe/bsw@0 | 14 "%[[a-z]+%]", |
jbe/bsw@0 | 15 function(char) |
jbe/bsw@0 | 16 if char == "[eq]" then return "=" |
jbe/bsw@0 | 17 elseif char == "[s]" then return ";" |
jbe/bsw@0 | 18 elseif char == "[o]" then return "[" |
jbe/bsw@0 | 19 elseif char == "[c]" then return "]" |
jbe/bsw@0 | 20 else end |
jbe/bsw@0 | 21 end |
jbe/bsw@0 | 22 ) |
jbe/bsw@0 | 23 ) |
jbe/bsw@0 | 24 end |
jbe/bsw@0 | 25 |
jbe/bsw@0 | 26 function slot.restore_all(blob) |
jbe/bsw@0 | 27 slot.reset_all() |
jbe/bsw@0 | 28 for encoded_key, encoded_value in string.gmatch(blob, "([^=;]*)=([^=;]*)") do |
jbe/bsw@0 | 29 local key, value = decode(encoded_key), decode(encoded_value) |
jbe/bsw@0 | 30 slot._data[key].string_fragments = { value } |
jbe/bsw@0 | 31 end |
jbe/bsw@0 | 32 end |