2014-08-25 00:38:09 -04:00
|
|
|
#include "picrin.h"
|
2016-02-20 11:13:16 -05:00
|
|
|
#include "picrin/private/object.h"
|
2014-08-25 00:38:09 -04:00
|
|
|
|
2016-02-18 10:50:13 -05:00
|
|
|
bool
|
2016-02-20 07:16:10 -05:00
|
|
|
pic_data_p(pic_state *pic, pic_value obj, const pic_data_type *type)
|
2016-02-18 10:50:13 -05:00
|
|
|
{
|
2016-02-20 07:16:10 -05:00
|
|
|
if (pic_type(pic, obj) != PIC_TYPE_DATA) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return type == NULL || pic_data_ptr(pic, obj)->type == type;
|
2016-02-18 10:50:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2016-02-21 05:19:35 -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)
|
|
|
|
{
|
2016-02-21 06:32:00 -05:00
|
|
|
struct data *data;
|
2016-02-18 10:50:13 -05:00
|
|
|
|
2016-02-21 06:32:00 -05:00
|
|
|
data = (struct data *)pic_obj_alloc(pic, sizeof(struct data), PIC_TYPE_DATA);
|
2016-02-18 10:50:13 -05:00
|
|
|
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
|
|
|
}
|