hello,
I would like to use an API that take a pointer as argument ( lets say a
@[float][3] ) and I start from array(float, 3).
How can I convert from one to another ?
I have seen this definition in array.dats
assume array_viewt0ype_int_type
(a:viewt@ype, n:int) = [l:addr] @{
data= ptr l, view= vbox (array_v (a, n, l))
} // end of [array_viewt0ype_int_type]
that make me think I can do like this :
staload _(anonymous)=“prelude/DATS/array.dats”
implement main(argc, argv) = let
fun {a:t@ype} vec3_create (x: a, y: a, z: a): array(a, 3) = let
val (_, pf|p, sz) = $arrsz {a}(x, y, z)
in array_make_view_ptr(pf|p) end
val my_vec3: array(float, 3) = vec3_create(1.0f, 0.0f, 0.0f)
val () = printf("%f, %f, %f\n", @(double_of my_vec3[0], double_of my_vec3[
1], double_of my_vec3[2]))
fun do_nothing (t: &(@[float][3])): void = ()
val p = my_vec3.data // <- ERROR
prval vbox pf = my_vec3.view
in
do_nothing(!p)
end
Unfortunately I have this error :
arr.dats: 445(line=12, offs=11) – 457(line=12, offs=23): error(3): the
type [S2Eapp(S2Ecst(array_viewt0ype_int_type); S2Ecst(float), S2Eint(3))]
is expected to be a record or union but it is not.
I took the code from array.dats :
fun{a:t@ype}
array_get_elt_at {n:int}
{i:nat | i < n} (A: array (a, n), i: size_t i):<!ref> a
…
implement{a}
array_get_elt_at (A, i) = let
val A_data = A.data; prval vbox pf = A.view in !A_data.[i]
end // end of [array_get_elt]
thanks