picrin/extlib/benz/data.c

27 lines
587 B
C
Raw Normal View History

2014-08-25 00:38:09 -04:00
#include "picrin.h"
2016-02-18 10:50:13 -05:00
#include "picrin/object.h"
2014-08-25 00:38:09 -04:00
2016-02-18 10:50:13 -05:00
bool
pic_data_type_p(pic_state *pic, pic_value obj, const pic_data_type *type)
{
2016-02-19 09:30:47 -05:00
return pic_data_p(pic, obj) && pic_data_ptr(pic, obj)->type == type;
2016-02-18 10:50:13 -05:00
}
void *
2016-02-19 09:30:47 -05:00
pic_data(pic_state PIC_UNUSED(*pic), pic_value data)
2016-02-18 10:50:13 -05:00
{
2016-02-19 09:30:47 -05:00
return pic_data_ptr(pic, data)->data;
2016-02-18 10:50:13 -05:00
}
2016-02-19 09:30:47 -05:00
pic_value
2016-02-18 10:50:13 -05:00
pic_data_value(pic_state *pic, void *userdata, const pic_data_type *type)
{
struct pic_data *data;
data = (struct pic_data *)pic_obj_alloc(pic, sizeof(struct pic_data), PIC_TYPE_DATA);
data->type = type;
data->data = userdata;
2016-02-19 09:30:47 -05:00
return pic_obj_value(data);
2016-02-18 10:50:13 -05:00
}