forked from Wiladams/LAPHLibs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintutils.lua
More file actions
52 lines (41 loc) · 981 Bytes
/
printutils.lua
File metadata and controls
52 lines (41 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
local ffi = require "ffi"
local ctype = require "cctype"
local function bytestohex(data, datalen)
datalen = datalen or #data
data = ffi.cast("const uint8_t *", data)
local aline = {}
for i=0, datalen-1 do
table.insert(aline, string.format("%02x", data[i]));
if i%16 == 15 then
table.insert(aline,'\n');
else
table.insert(aline, ":");
end
end
return table.concat(aline)
end
local function bytestohexstring(data, datalen)
local aline = {}
for i=0, datalen-1 do
if ctype.isprint(data[i]) then
table.insert(aline, string.char(data[i]));
else
--table.insert(aline, string.format("%02x", data[i]));
table.insert(aline, '.');
end
if i%16 == 15 then
table.insert(aline,'\n');
else
--table.insert(aline, ":");
end
end
return table.concat(aline)
end
local function blobtohex(blob)
return bytestohex(blob.Data, blob.Length);
end
return {
bytestohex = bytestohex;
bytestohexstring = bytestohexstring;
blobtohex = blobtohex;
}