aboutsummaryrefslogtreecommitdiff
path: root/guile_type_helpers.c
blob: 00c68b18153bf62805a2206172289617bfec39d3 (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
#include "guile_type_helpers.h"

#include "macro.h"

SCM scm_from_strbuf(strbuf* s) {
	if (s->scm == NULL) {
		s->scm = scm_from_utf8_stringn (s->mem, s->len - 1);
		scm_gc_protect_object(s->scm);
	}

	return s->scm;
}

SCM scm_from_vector(VECT(vcomponent)* vect, SCM element_type) {
	SCM l = SCM_EOL;
	for (size_t i = 0; i < vect->length; i++) {
		vcomponent* v = GET(VECT(vcomponent))(vect, i);
		if (v->scm == NULL) {
			v->scm = scm_make_foreign_object_1 (element_type, v);
			scm_gc_protect_object(v->scm);
		}
		l = scm_cons(v->scm, l);
	}
	return scm_reverse(l);
}