summaryrefslogtreecommitdiff
path: root/lua/setup.lua
blob: 5af328e76562968836d5a805b93fee794320a599 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
print"============================================"

local keepgoing = nil

for _,v in ipairs(arg) do
  if v == "-k" then
    keepgoing = true
  end
end

require"net"

DEV="en0"

-- Quote a string into lua form (including the non-printable characters from
-- 0-31, and from 127-255).
function q(_)
  local fmt = string.format
  local _ = fmt("%q", _)

  _ = string.gsub(_, "\\\n", "\\n")
  _ = string.gsub(_, "[%z\1-\31,\127-\255]", function (x)
    --print("x=", x)
    return fmt("\\%03d",string.byte(x))
  end)

  return _
end

function h(_)
  local fmt = string.format
  _ = string.gsub(_, ".", function (x)
    return fmt("%02x",string.byte(x))
  end)

  return _
end

function dump(n, size)
  local b = n:block()
  print(">")
  print(n:dump())
  print("size="..#b)
  --print("q=[["..q(b).."]]")
  print("h=[["..h(b).."]]")

  if size then
    assert(#b == size, "block's size is not expected, "..size)
  end
end

function test(n, f)
    print""
    print""
    print("=test: "..n)

    if not keepgoing then
        f()
        print("+pass: "..n)
    else
        local ok, emsg = pcall(f)
        if not ok then
            print("! FAIL: "..n)
        else
            print("+pass: "..n)
        end
    end
end

function hex_dump(s)
    print(h(s))
end