diff --git a/src/core/capi.c b/src/core/capi.c index 4740b31f..9f6234ad 100644 --- a/src/core/capi.c +++ b/src/core/capi.c @@ -107,7 +107,7 @@ Janet janet_getmethod(const uint8_t *method, const JanetMethod *methods) { return janet_wrap_cfunction(methods->cfun); methods++; } - janet_panicf("unknown method %S invoked", method); + janet_panicf("unknown method :%S invoked", method); return janet_wrap_nil(); } diff --git a/src/core/typedarray.c b/src/core/typedarray.c index 586ab36b..dc4ab824 100644 --- a/src/core/typedarray.c +++ b/src/core/typedarray.c @@ -159,10 +159,14 @@ static void ta_view_unmarshal(void *p, JanetMarshalContext *ctx) { view->as.u8 = view->buffer->data + offset; } +static JanetMethod tarray_view_methods[]; + static Janet ta_getter(void *p, Janet key) { Janet value; size_t index, i; JanetTArrayView *array = p; + if (janet_checktype(key, JANET_KEYWORD)) + return janet_getmethod(janet_unwrap_keyword(key), tarray_view_methods); if (!janet_checksize(key)) janet_panic("expected size as key"); index = (size_t) janet_unwrap_number(key); i = index * array->stride; @@ -551,6 +555,15 @@ static const JanetReg ta_cfuns[] = { {NULL, NULL, NULL} }; +static JanetMethod tarray_view_methods[] = { + {"length", cfun_typed_array_size}, + {"properties", cfun_typed_array_properties}, + {"copy-bytes", cfun_typed_array_copy_bytes}, + {"swap-bytes", cfun_typed_array_swap_bytes}, + {"slice", cfun_typed_array_slice}, + {NULL, NULL} +}; + /* Module entry point */ void janet_lib_typed_array(JanetTable *env) { janet_core_cfuns(env, NULL, ta_cfuns);