]>
Commit | Line | Data |
---|---|---|
5b1311fb MHS |
1 | --[[\r |
2 | This may be moved to a separate library at some point (Holiman)\r | |
3 | --]]\r | |
4 | local Utils = \r | |
5 | {\r | |
6 | -- Asks the user for Yes or No\r | |
7 | confirm = function(message, ...)\r | |
8 | local answer\r | |
9 | message = message .. " [y/n] ?"\r | |
10 | repeat\r | |
11 | io.write(message)\r | |
12 | io.flush()\r | |
13 | answer=io.read()\r | |
14 | if answer == 'Y' or answer == "y" then\r | |
15 | return true\r | |
16 | elseif answer == 'N' or answer == 'n' then \r | |
17 | return false\r | |
18 | end\r | |
19 | until false\r | |
20 | end,\r | |
21 | ---\r | |
22 | -- Asks the user for input\r | |
23 | input = function (message , default)\r | |
24 | local answer\r | |
25 | if default ~= nil then\r | |
26 | message = message .. " (default: ".. default.. " )"\r | |
27 | end\r | |
28 | message = message .." \n > "\r | |
29 | io.write(message)\r | |
30 | io.flush()\r | |
31 | answer=io.read()\r | |
32 | if answer == '' then answer = default end\r | |
33 | \r | |
34 | return answer\r | |
35 | end,\r | |
36 | --\r | |
37 | -- Converts DECIMAL to HEX\r | |
38 | ConvertDec2Hex = function(IN)\r | |
39 | local B,K,OUT,I,D=16,"0123456789ABCDEF","",0\r | |
40 | while IN>0 do\r | |
41 | I=I+1\r | |
42 | IN,D=math.floor(IN/B),math.mod(IN,B)+1\r | |
43 | OUT=string.sub(K,D,D)..OUT\r | |
44 | end\r | |
45 | return OUT\r | |
46 | end,\r | |
47 | ---\r | |
48 | -- Convert Byte array to string of hex\r | |
49 | ConvertBytes2String = function(bytes)\r | |
50 | s = {}\r | |
51 | for i = 1, #(bytes) do\r | |
52 | s[i] = string.format("%02X",bytes[i]) \r | |
53 | end\r | |
54 | return table.concat(s)\r | |
55 | end, \r | |
56 | }\r | |
57 | return Utils |