check io.open return

This commit is contained in:
Daniel Barlow 2024-09-26 22:11:37 +01:00
parent ba3795e3f2
commit 9ef1947211
1 changed files with 8 additions and 8 deletions

View File

@ -8,6 +8,12 @@
(local pkey (require :openssl.pkey))
(local bignum (require :openssl.bignum))
;; ncall is the opposite of pcall: "non-protected call"
(macro ncall [f]
`(case ,f
ok# ok#
(nil err#) (error err#)))
(fn string->bignum [bytes]
(bignum.new
(string.format
@ -34,10 +40,10 @@
(out:write_chunk text true))
(fn slurp [filename]
(with-open [f (io.open filename "r")] (f:read "*a")))
(with-open [f (ncall (io.open filename "r"))] (f:read "*a")))
(fn read-line [filename]
(with-open [f (io.open filename "r")] (f:read "l")))
(with-open [f (ncall (io.open filename "r"))] (f:read "l")))
(fn assoc [tbl k v & more]
(tset tbl k v)
@ -106,12 +112,6 @@
_
(send-error out 404 "not found"))))
;; ncall is the opposite of pcall: "non-protected call"
(macro ncall [f]
`(case ,f
ok# ok#
(nil err#) (error err#)))
(fn new-server []
(let [(addr port) (string.match options.bind-address "(.+):(%d+)$")]
(case (server.listen