diff --git a/examples/numarray/build.janet b/examples/numarray/build.janet index 75d688d8..2e682568 100644 --- a/examples/numarray/build.janet +++ b/examples/numarray/build.janet @@ -4,7 +4,7 @@ :name "numarray" :source @["numarray.c"]) -(import build/numarray :prefix "") +(import build/numarray :as numarray) (def a (numarray/new 30)) (print (get a 20)) diff --git a/examples/numarray/numarray.c b/examples/numarray/numarray.c index 5b533927..ac411fad 100644 --- a/examples/numarray/numarray.c +++ b/examples/numarray/numarray.c @@ -100,12 +100,12 @@ Janet num_array_get(void *p, Janet key) { static const JanetReg cfuns[] = { { - "numarray/new", num_array_new, + "new", num_array_new, "(numarray/new size)\n\n" "Create new numarray" }, { - "numarray/scale", num_array_scale, + "scale", num_array_scale, "(numarray/scale numarray factor)\n\n" "scale numarray by factor" }, diff --git a/src/core/parse.c b/src/core/parse.c index 21b167f5..6b9d2ed2 100644 --- a/src/core/parse.c +++ b/src/core/parse.c @@ -257,12 +257,24 @@ static int escape1(JanetParser *p, JanetParseState *state, uint8_t c) { static int stringend(JanetParser *p, JanetParseState *state) { Janet ret; + uint8_t *bufstart = p->buf; + int32_t buflen = (int32_t) p->bufcount; + if (state->flags & PFLAG_LONGSTRING) { + /* Check for leading newline character so we can remove it */ + if (bufstart[0] == '\n') { + bufstart++; + buflen--; + } + if (buflen > 0 && bufstart[buflen - 1] == '\n') { + buflen--; + } + } if (state->flags & PFLAG_BUFFER) { - JanetBuffer *b = janet_buffer((int32_t)p->bufcount); - janet_buffer_push_bytes(b, p->buf, (int32_t)p->bufcount); + JanetBuffer *b = janet_buffer(buflen); + janet_buffer_push_bytes(b, bufstart, buflen); ret = janet_wrap_buffer(b); } else { - ret = janet_wrap_string(janet_string(p->buf, (int32_t)p->bufcount)); + ret = janet_wrap_string(janet_string(bufstart, buflen)); } p->bufcount = 0; popstate(p, ret);