Comparison

util/serialization.lua @ 9865:37278b420c74

util.serialization: Use util.hex
author Kim Alvefur <zash@zash.se>
date Sun, 17 Mar 2019 21:25:33 +0100
parent 9864:9d80e679c371
child 10061:5c71693c8345
comparison
equal deleted inserted replaced
9864:9d80e679c371 9865:37278b420c74
14 local s_rep = string.rep; 14 local s_rep = string.rep;
15 local s_char = string.char; 15 local s_char = string.char;
16 local s_match = string.match; 16 local s_match = string.match;
17 local t_concat = table.concat; 17 local t_concat = table.concat;
18 18
19 local to_hex = require "util.hex".to;
20
19 local pcall = pcall; 21 local pcall = pcall;
20 local envload = require"util.envload".envload; 22 local envload = require"util.envload".envload;
21 23
22 local pos_inf, neg_inf = math.huge, -math.huge; 24 local pos_inf, neg_inf = math.huge, -math.huge;
23 local m_type = math.type or function (n) 25 local m_type = math.type or function (n)
24 return n % 1 == 0 and n <= 9007199254740992 and n >= -9007199254740992 and "integer" or "float"; 26 return n % 1 == 0 and n <= 9007199254740992 and n >= -9007199254740992 and "integer" or "float";
25 end; 27 end;
26
27 local char_to_hex = {};
28 for i = 0,255 do
29 char_to_hex[s_char(i)] = s_format("%02x", i);
30 end
31
32 local function to_hex(s)
33 return (s_gsub(s, ".", char_to_hex));
34 end
35 28
36 local function rawpairs(t) 29 local function rawpairs(t)
37 return next, t, nil; 30 return next, t, nil;
38 end 31 end
39 32