about summary refs log tree commit diff
path: root/src/guile_api.cpp
blob: e3ef48214158675e707540a46d58d55df6e2f8a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <guile_api.h>

namespace gemmaguile {

    void global_start_guile() {
        scm_init_guile();
    }

    string global_guile_version() {
        SCM version_scm = scm_version();
        char* c_str = scm_to_utf8_string(version_scm);
        string version_str(c_str);
        free(c_str);  // Must free the allocated memory

        return version_str;
    }

    SCM make_floats()
    {
        return scm_call_0(scm_c_public_ref("example", "make-floats"));
    }

    void use_floats()
    {
        SCM vec = make_floats();

        scm_t_array_handle handle;
        size_t len;
        ssize_t inc;
        const SCM *elt;

        const double *ny = scm_f64vector_elements (vec,&handle,&len,&inc);
        for (size_t i = 0; i < len; i++) {
            printf("elem %zu = %f\n", i, ny[i]);
        }
        scm_array_handle_release (&handle);
    }

    void start_test() {
        scm_c_primitive_load("src/guile/examples.scm");
        use_floats();
    }

}