From 5112ed77d6d44ce23c9e7a39afd8b2e3c30bd3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Pospi=CC=81s=CC=8Cil?= Date: Thu, 9 Dec 2021 11:12:08 +0100 Subject: [PATCH 1/2] Fix test import, and add sum as library fn too --- examples/numarray/numarray.c | 5 +++++ examples/numarray/test/numarray_tests.janet | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/numarray/numarray.c b/examples/numarray/numarray.c index 359fe087..3c912933 100644 --- a/examples/numarray/numarray.c +++ b/examples/numarray/numarray.c @@ -109,6 +109,11 @@ static const JanetReg cfuns[] = { "(numarray/scale numarray factor)\n\n" "scale numarray by factor" }, + { + "sum", num_array_sum, + "(numarray/sum numarray)\n\n" + "sums numarray" + }, {NULL, NULL, NULL} }; diff --git a/examples/numarray/test/numarray_tests.janet b/examples/numarray/test/numarray_tests.janet index 5ae34bba..60728525 100644 --- a/examples/numarray/test/numarray_tests.janet +++ b/examples/numarray/test/numarray_tests.janet @@ -1,4 +1,4 @@ -(import build/numarray) +(import /build/numarray) (def a (numarray/new 30)) (print (get a 20)) From f586a8a9dc2a9d326f70776d507c0cbbed14788b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Pospi=CC=81s=CC=8Cil?= Date: Thu, 9 Dec 2021 11:18:05 +0100 Subject: [PATCH 2/2] Add length to method and lib fn to numarray --- examples/numarray/numarray.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/numarray/numarray.c b/examples/numarray/numarray.c index 3c912933..52ea9e66 100644 --- a/examples/numarray/numarray.c +++ b/examples/numarray/numarray.c @@ -76,9 +76,16 @@ void num_array_put(void *p, Janet key, Janet value) { } } +static Janet num_array_length(int32_t argc, Janet *argv) { + janet_fixarity(argc, 1); + num_array *array = (num_array *)janet_getabstract(argv, 0, &num_array_type); + return janet_wrap_number(array->size); +} + static const JanetMethod methods[] = { {"scale", num_array_scale}, {"sum", num_array_sum}, + {"length", num_array_length}, {NULL, NULL} };