mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-30 23:23:07 +00:00 
			
		
		
		
	Allow method calls on typed arrays.
This commit is contained in:
		| @@ -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(); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose