comparison util/rsm.lua @ 10764:1fbfcc2f6805

util.rsm: Don't convert values to strings that should already be strings Causes util.stanza to throw an error, which helps detect mistakes
author Kim Alvefur <zash@zash.se>
date Thu, 23 Apr 2020 18:42:47 +0200
parents e0e2ae050d65
children c7948491c5e4
comparison
equal deleted inserted replaced
10763:e0e2ae050d65 10764:1fbfcc2f6805
8 -- 8 --
9 -- XEP-0313: Message Archive Management for Prosody 9 -- XEP-0313: Message Archive Management for Prosody
10 -- 10 --
11 11
12 local stanza = require"util.stanza".stanza; 12 local stanza = require"util.stanza".stanza;
13 local tostring, tonumber = tostring, tonumber; 13 local tonumber = tonumber;
14 local s_format = string.format; 14 local s_format = string.format;
15 local type = type; 15 local type = type;
16 local pairs = pairs; 16 local pairs = pairs;
17 17
18 local function inttostr(n) 18 local function inttostr(n)
50 local element_generators = setmetatable({ 50 local element_generators = setmetatable({
51 first = function(st, data) 51 first = function(st, data)
52 if type(data) == "table" then 52 if type(data) == "table" then
53 st:tag("first", { index = inttostr(data.index) }):text(data[1]):up(); 53 st:tag("first", { index = inttostr(data.index) }):text(data[1]):up();
54 else 54 else
55 st:tag("first"):text(tostring(data)):up(); 55 st:tag("first"):text(data):up();
56 end 56 end
57 end; 57 end;
58 before = function(st, data) 58 before = function(st, data)
59 if data == true then 59 if data == true then
60 st:tag("before"):up(); 60 st:tag("before"):up();
61 else 61 else
62 st:tag("before"):text(tostring(data)):up(); 62 st:tag("before"):text(data):up();
63 end 63 end
64 end; 64 end;
65 max = function (st, data) 65 max = function (st, data)
66 st:tag("max"):text(inttostr(data)):up(); 66 st:tag("max"):text(inttostr(data)):up();
67 end; 67 end;
69 st:tag("count"):text(inttostr(data)):up(); 69 st:tag("count"):text(inttostr(data)):up();
70 end; 70 end;
71 }, { 71 }, {
72 __index = function(_, name) 72 __index = function(_, name)
73 return function(st, data) 73 return function(st, data)
74 st:tag(name):text(tostring(data)):up(); 74 st:tag(name):text(data):up();
75 end 75 end
76 end; 76 end;
77 }); 77 });
78 78
79 79