picrin/lib/data.c

36 lines
665 B
C
Raw Normal View History

2017-03-28 10:09:40 -04:00
/**
* See Copyright Notice in picrin.h
*/
2014-08-25 00:38:09 -04:00
#include "picrin.h"
2017-05-05 23:53:20 -04:00
#include "value.h"
2017-03-28 10:09:40 -04:00
#include "object.h"
2017-05-05 23:53:20 -04:00
#include "state.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
{
if (pic_type(pic, obj) != PIC_TYPE_DATA) {
2016-02-20 07:16:10 -05:00
return false;
}
return type == NULL || data_ptr(pic, obj)->type == type;
2016-02-18 10:50:13 -05:00
}
void *
2017-05-06 12:36:56 -04:00
pic_data(pic_state *pic, pic_value data)
2016-02-18 10:50:13 -05:00
{
return 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
2017-04-12 00:18:06 -04:00
data = (struct data *)pic_obj_alloc(pic, PIC_TYPE_DATA);
2016-02-18 10:50:13 -05:00
data->type = type;
data->data = userdata;
return obj_value(pic, data);
2016-02-18 10:50:13 -05:00
}