Software /
code /
prosody
Comparison
util/template.lua @ 7197:ff514c1b1c27
util.template: Use separate variables for source and compiled function [luacheck]
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 25 Feb 2016 22:32:13 +0100 |
parent | 7196:94ec474debf5 |
child | 8418:ad1e10c93b41 |
comparison
equal
deleted
inserted
replaced
7196:94ec474debf5 | 7197:ff514c1b1c27 |
---|---|
65 return lookup[stanza]; | 65 return lookup[stanza]; |
66 end | 66 end |
67 local function create_cloner(stanza, chunkname) | 67 local function create_cloner(stanza, chunkname) |
68 local lookup = {}; | 68 local lookup = {}; |
69 local name = create_clone_string(stanza, lookup, ""); | 69 local name = create_clone_string(stanza, lookup, ""); |
70 local f = "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 f = f.."local _"..i.."="..lookup[i]..";"; | 72 src = src.."local _"..i.."="..lookup[i]..";"; |
73 end | 73 end |
74 f = f.."return "..name..";end"; | 74 src = src.."return "..name..";end"; |
75 local f,err = loadstring(f, chunkname); | 75 local f,err = loadstring(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 }; |