Software /
code /
prosody
Comparison
util/serialization.lua @ 5021:85b2689dbcfe
Eliminate direct setfenv usage
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Fri, 08 Jun 2012 05:04:38 +0200 |
parent | 3745:87f6eabd90c9 |
child | 5776:bd0ff8ae98a8 |
comparison
equal
deleted
inserted
replaced
5020:ef1eb65acbba | 5021:85b2689dbcfe |
---|---|
14 local error = error; | 14 local error = error; |
15 local pairs = pairs; | 15 local pairs = pairs; |
16 local next = next; | 16 local next = next; |
17 | 17 |
18 local loadstring = loadstring; | 18 local loadstring = loadstring; |
19 local setfenv = setfenv; | |
20 local pcall = pcall; | 19 local pcall = pcall; |
21 | 20 |
22 local debug_traceback = debug.traceback; | 21 local debug_traceback = debug.traceback; |
23 local log = require "util.logger".init("serialization"); | 22 local log = require "util.logger".init("serialization"); |
23 local envload = require"util.envload".envload; | |
24 | |
24 module "serialization" | 25 module "serialization" |
25 | 26 |
26 local indent = function(i) | 27 local indent = function(i) |
27 return string_rep("\t", i); | 28 return string_rep("\t", i); |
28 end | 29 end |
82 end | 83 end |
83 | 84 |
84 function deserialize(str) | 85 function deserialize(str) |
85 if type(str) ~= "string" then return nil; end | 86 if type(str) ~= "string" then return nil; end |
86 str = "return "..str; | 87 str = "return "..str; |
87 local f, err = loadstring(str, "@data"); | 88 local f, err = envload(str, "@data", {}); |
88 if not f then return nil, err; end | 89 if not f then return nil, err; end |
89 setfenv(f, {}); | |
90 local success, ret = pcall(f); | 90 local success, ret = pcall(f); |
91 if not success then return nil, ret; end | 91 if not success then return nil, ret; end |
92 return ret; | 92 return ret; |
93 end | 93 end |
94 | 94 |