mirror of
https://github.com/janet-lang/janet
synced 2024-12-26 00:10:27 +00:00
Add some library functions and add newline character to reading line
from file.
This commit is contained in:
parent
c76b08cecc
commit
7bfb3145cb
@ -130,3 +130,33 @@
|
||||
|
||||
(fn [x] (print (pp1 @{} @"" x)))
|
||||
))
|
||||
|
||||
(defn pairs [x]
|
||||
(var lastkey (next x nil))
|
||||
{
|
||||
:more (fn [] lastkey)
|
||||
:next (fn []
|
||||
(def ret (tuple lastkey (get x lastkey)))
|
||||
(varset! lastkey (next x lastkey))
|
||||
ret)
|
||||
})
|
||||
|
||||
(defn keys [x]
|
||||
(var lastkey (next x nil))
|
||||
{
|
||||
:more (fn [] lastkey)
|
||||
:next (fn []
|
||||
(def ret lastkey)
|
||||
(varset! lastkey (next x lastkey))
|
||||
ret)
|
||||
})
|
||||
|
||||
(defn values [x]
|
||||
(var lastkey (next x nil))
|
||||
{
|
||||
:more (fn [] lastkey)
|
||||
:next (fn []
|
||||
(def ret (get x lastkey))
|
||||
(varset! lastkey (next x lastkey))
|
||||
ret)
|
||||
})
|
||||
|
@ -187,10 +187,8 @@ static int dst_io_fread(DstArgs args) {
|
||||
} else if (!dst_cstrcmp(sym, ":line")) {
|
||||
for (;;) {
|
||||
int x = fgetc(iof->file);
|
||||
if (x == EOF || x == '\n') {
|
||||
break;
|
||||
}
|
||||
if (dst_buffer_push_u8(b, (uint8_t)x)) return dst_throw(args, "buffer overflow");
|
||||
if (x != EOF && dst_buffer_push_u8(b, (uint8_t)x)) return dst_throw(args, "buffer overflow");
|
||||
if (x == EOF || x == '\n') break;
|
||||
}
|
||||
return dst_return(args, dst_wrap_buffer(b));
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user