diff --git a/include/picrin.h b/include/picrin.h index 17c7a7d4..189a295b 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -103,6 +103,7 @@ pic_value pic_str_new_cstr(pic_state *, const char *); struct pic_vector *pic_vec_new(pic_state *, size_t); struct pic_vector *pic_vec_new_from_list(pic_state *, pic_value); +void pic_vec_extend_ip(pic_state *, struct pic_vector *, int); int pic_parse_file(pic_state *, FILE *file, pic_value *); int pic_parse_cstr(pic_state *, const char *, pic_value *); diff --git a/src/vector.c b/src/vector.c index 9e695647..e4137680 100644 --- a/src/vector.c +++ b/src/vector.c @@ -32,6 +32,19 @@ pic_vec_new_from_list(pic_state *pic, pic_value data) return vec; } +void +pic_vec_extend_ip(pic_state *pic, struct pic_vector *vec, int size) +{ + int len, i; + + len = vec->len; + vec->len = size; + vec->data = (pic_value *)pic_realloc(pic, vec->data, sizeof(pic_value) * size); + for (i = len; i < size; ++i) { + vec->data[i] = pic_false_value(); + } +} + static pic_value pic_vec_vector_p(pic_state *pic) {