picrin/extlib/benz/data.c

29 lines
595 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)
{
return pic_data_p(pic, obj) && pic_data_ptr(obj)->type == type;
}
void *
pic_data(pic_state *pic, pic_value data)
{
pic_assert_type(pic, data, data);
return pic_data_ptr(data)->data;
}
struct pic_data *
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;
return data;
}