~technomancy/shevek

4214f7bf5e21dd8bbeeb61d89e0ddebebe0e6303 — Phil Hagelberg 1 year, 4 months ago a7a5f1b
Update for latest fennel idioms.
1 files changed, 8 insertions(+), 12 deletions(-)

M shevek.fnl
M shevek.fnl => shevek.fnl +8 -12
@@ 2,10 2,7 @@
(local bencode (require :bencode))

(local active-requests {})
(var counter 0)
(var session nil)
(var ns nil)
(var prompt "=> ")
(var (counter prompt session) (values 0 "=> " nil))

(λ count [tbl]
  (var i 0)


@@ 22,7 19,7 @@
  (tset active-requests msg.id true)
  (when (not msg.session)
    (set msg.session session))
  (assert (: conn :send (bencode.encode msg))))
  (assert (conn:send (bencode.encode msg))))

(λ send-input [?session]
  (let [input (io.read)]


@@ 40,7 37,6 @@
  (when response.value (print response.value))

  (when response.ns
    (set ns response.ns)
    (set prompt (.. response.ns "=> ")))

  (when response.status


@@ 56,7 52,7 @@
    (print "   " (view response) (view active-requests))))

(λ receive [conn]
  (let [(data err part) (: conn :receive "*a")]
  (let [(data _ part) (conn:receive "*a")]
    (when (or data (and part (not= part "")))
      (let [(decodeds d-err) (bencode.decode_all (or data part))]
        (if decodeds


@@ 65,17 61,17 @@
            (print (.. "Decoding error: " d-err (or data part) "\n"))))
      true)))

(local [host port] (let [(host port) (: (. arg 1) :match "(.*):(.*)")]
(local (host port) (let [(host port) (: (or (. arg 1) "") :match "(.*):(.*)")]
                     (if host
                         [host port]
                         ["localhost" (. arg 1)])))
                         (values host port)
                         (values "localhost" (. arg 1)))))

(when (not port)
  (: io.stderr :write "USAGE: shevek [HOST:]PORT\n")
  (io.stderr:write "USAGE: shevek [HOST:]PORT\n")
  (os.exit 1))

(local conn (let [c (assert (socket.connect host (tonumber port)))]
              (: c :settimeout 0.01)
              (c:settimeout 0.01)
              (send {:op :clone} c)
              c))