Comparison

util/datamapper.lua @ 11453:f0037234b2e9

util.datamapper: Enumerated elements E.g. error conditions or chat states.
author Kim Alvefur <zash@zash.se>
date Fri, 12 Mar 2021 01:33:15 +0100
parent 11451:ee4f2296e7df
child 11454:1d9c1893cc5e
comparison
equal deleted inserted replaced
11452:c799bac7ca59 11453:f0037234b2e9
18 local prefix = nil 18 local prefix = nil
19 local is_attribute = false 19 local is_attribute = false
20 local is_text = false 20 local is_text = false
21 local name_is_value = false; 21 local name_is_value = false;
22 local single_attribute 22 local single_attribute
23 local enums
23 24
24 local proptype 25 local proptype
25 if type(propschema) == "table" then 26 if type(propschema) == "table" then
26 proptype = propschema.type 27 proptype = propschema.type
27 elseif type(propschema) == "string" then 28 elseif type(propschema) == "string" then
48 name_is_value = true 49 name_is_value = true
49 elseif propschema.xml.x_single_attribute then 50 elseif propschema.xml.x_single_attribute then
50 51
51 single_attribute = propschema.xml.x_single_attribute 52 single_attribute = propschema.xml.x_single_attribute
52 end 53 end
54 if propschema["const"] then
55 enums = {propschema["const"]}
56 elseif propschema["enum"] then
57 enums = propschema["enum"]
58 end
53 end 59 end
54 60
55 if name_is_value then 61 if name_is_value then
56 local c = s:get_child(nil, namespace); 62 local c
63 if proptype == "boolean" then
64 c = s:get_child(name, namespace);
65 elseif enums and proptype == "string" then
66
67 for i = 1, #enums do
68 c = s:get_child(enums[i], namespace);
69 if c then
70 break
71 end
72 end
73 else
74 c = s:get_child(nil, namespace);
75 end
57 if c and proptype == "string" then 76 if c and proptype == "string" then
58 out[prop] = c.name; 77 out[prop] = c.name;
59 elseif proptype == "boolean" and c then 78 elseif proptype == "boolean" and c then
60 out[prop] = true; 79 out[prop] = true;
61 end 80 end