Last active
August 29, 2015 14:00
-
-
Save nyuichi/11207872 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* C-side API | |
*/ | |
struct my_data { | |
// blah blah blah | |
}; | |
struct my_data * | |
create_my_data () | |
{ | |
return malloc(sizeof(struct my_data)); | |
} | |
void | |
finalize_my_data (void *my_data) { | |
struct my_data *md = my_data; | |
free(md); | |
} | |
/* | |
* picrin-side FFI interface | |
*/ | |
static const pic_data_type my_data = { "my-data", finalize_my_data }; | |
static pic_value | |
pic_create_my_data(pic_state *pic) | |
{ | |
struct my_data *md; | |
struct pic_data *dat; | |
pic_get_args(pic, ""); // no args here | |
md = create_my_data(); | |
data = pic_data_alloc(pic, &my_data, md); | |
return pic_obj_value(data); | |
} | |
void | |
pic_init_my_data(pic_state *pic) | |
{ | |
pic_defun(pic, "create-my-data", pic_create_my_data); // (create-my-data) | |
} | |
// at last you need to modify src/init.c to call my pic_init_my_data. | |
// I should have made a cmake hook to call this kind of extension initializers | |
// but I forgot about the detail... | |
// When I remember or write it up from scratch, I'll revise this tutorial. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment