Software /
code /
prosody
Comparison
teal-src/util/datamapper.tl @ 11459:86904555bffc
teal: Use new integer support in Teal 0.13.0
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 18 Mar 2021 23:16:41 +0100 |
parent | 11458:0e00fa518688 |
child | 11461:766b0eddd12c |
comparison
equal
deleted
inserted
replaced
11458:0e00fa518688 | 11459:86904555bffc |
---|---|
15 -- x_single_attribute for <tag attr="this"/> | 15 -- x_single_attribute for <tag attr="this"/> |
16 -- | 16 -- |
17 -- TODO arrays | 17 -- TODO arrays |
18 -- TODO pointers | 18 -- TODO pointers |
19 -- TODO cleanup / refactor | 19 -- TODO cleanup / refactor |
20 -- TODO s/number/integer/ once we have appropriate math.type() compat | |
20 -- | 21 -- |
21 | 22 |
22 local st = require "util.stanza"; | 23 local st = require "util.stanza"; |
23 local js = require "util.jsonschema" | 24 local js = require "util.jsonschema" |
24 | 25 |
244 | 245 |
245 if proptype == "string" and v is string then | 246 if proptype == "string" and v is string then |
246 out.attr[attr] = v | 247 out.attr[attr] = v |
247 elseif proptype == "number" and v is number then | 248 elseif proptype == "number" and v is number then |
248 out.attr[attr] = string.format("%g", v) | 249 out.attr[attr] = string.format("%g", v) |
249 elseif proptype == "integer" and v is number then | 250 elseif proptype == "integer" and v is number then -- TODO is integer |
250 out.attr[attr] = string.format("%d", v) | 251 out.attr[attr] = string.format("%d", v) |
251 elseif proptype == "boolean" then | 252 elseif proptype == "boolean" then |
252 out.attr[attr] = v and "1" or "0" | 253 out.attr[attr] = v and "1" or "0" |
253 end | 254 end |
254 elseif value_where == "in_text" then | 255 elseif value_where == "in_text" then |
264 | 265 |
265 if proptype == "string" and v is string then | 266 if proptype == "string" and v is string then |
266 propattr[single_attribute] = v | 267 propattr[single_attribute] = v |
267 elseif proptype == "number" and v is number then | 268 elseif proptype == "number" and v is number then |
268 propattr[single_attribute] = string.format("%g", v) | 269 propattr[single_attribute] = string.format("%g", v) |
269 elseif proptype == "integer" and v is number then | 270 elseif proptype == "integer" and v is number then -- TODO is integer |
270 propattr[single_attribute] = string.format("%d", v) | 271 propattr[single_attribute] = string.format("%d", v) |
271 elseif proptype == "boolean" and v is boolean then | 272 elseif proptype == "boolean" and v is boolean then |
272 propattr[single_attribute] = v and "1" or "0" | 273 propattr[single_attribute] = v and "1" or "0" |
273 end | 274 end |
274 out:tag(name, propattr):up(); | 275 out:tag(name, propattr):up(); |
286 end | 287 end |
287 elseif proptype == "string" and v is string then | 288 elseif proptype == "string" and v is string then |
288 out:text_tag(name, v, propattr) | 289 out:text_tag(name, v, propattr) |
289 elseif proptype == "number" and v is number then | 290 elseif proptype == "number" and v is number then |
290 out:text_tag(name, string.format("%g", v), propattr) | 291 out:text_tag(name, string.format("%g", v), propattr) |
291 elseif proptype == "integer" and v is number then | 292 elseif proptype == "integer" and v is number then -- TODO is integer |
292 out:text_tag(name, string.format("%d", v), propattr) | 293 out:text_tag(name, string.format("%d", v), propattr) |
293 elseif proptype == "boolean" and v is boolean then | 294 elseif proptype == "boolean" and v is boolean then |
294 out:text_tag(name, v and "1" or "0", propattr) | 295 out:text_tag(name, v and "1" or "0", propattr) |
295 elseif proptype == "object" and propschema is js.schema_t and v is table then | 296 elseif proptype == "object" and propschema is js.schema_t and v is table then |
296 local c = unparse(propschema, v, name, namespace); | 297 local c = unparse(propschema, v, name, namespace); |