Comparison

util/template.lua @ 8418:ad1e10c93b41

util.template: Use util.envload instead of loadstring which is deprecated in Lua 5.2
author Kim Alvefur <zash@zash.se>
date Thu, 23 Nov 2017 21:00:29 +0100
parent 7197:ff514c1b1c27
child 8555:4f0f5b49bb03
comparison
equal deleted inserted replaced
8417:e88db5668cfb 8418:ad1e10c93b41
2 local stanza_mt = require "util.stanza".stanza_mt; 2 local stanza_mt = require "util.stanza".stanza_mt;
3 local setmetatable = setmetatable; 3 local setmetatable = setmetatable;
4 local pairs = pairs; 4 local pairs = pairs;
5 local ipairs = ipairs; 5 local ipairs = ipairs;
6 local error = error; 6 local error = error;
7 local loadstring = loadstring; 7 local envload = require "util.envload".envload;
8 local debug = debug; 8 local debug = debug;
9 local t_remove = table.remove; 9 local t_remove = table.remove;
10 local parse_xml = require "util.xml".parse; 10 local parse_xml = require "util.xml".parse;
11 11
12 local _ENV = nil; 12 local _ENV = nil;
70 local src = "local setmetatable,stanza_mt=...;return function(data)"; 70 local src = "local setmetatable,stanza_mt=...;return function(data)";
71 for i=1,#lookup do 71 for i=1,#lookup do
72 src = src.."local _"..i.."="..lookup[i]..";"; 72 src = src.."local _"..i.."="..lookup[i]..";";
73 end 73 end
74 src = src.."return "..name..";end"; 74 src = src.."return "..name..";end";
75 local f,err = loadstring(src, chunkname); 75 local f,err = envload(src, chunkname);
76 if not f then error(err); end 76 if not f then error(err); end
77 return f(setmetatable, stanza_mt); 77 return f(setmetatable, stanza_mt);
78 end 78 end
79 79
80 local template_mt = { __tostring = function(t) return t.name end }; 80 local template_mt = { __tostring = function(t) return t.name end };