picrin/extlib/benz/include/picrin/data.h

39 lines
791 B
C
Raw Normal View History

2014-08-25 00:38:09 -04:00
/**
* See Copyright Notice in picrin.h
*/
2014-09-14 04:54:53 -04:00
#ifndef PICRIN_DATA_H
#define PICRIN_DATA_H
2014-08-25 00:38:09 -04:00
#if defined(__cplusplus)
extern "C" {
#endif
typedef struct {
const char *type_name;
void (*dtor)(pic_state *, void *);
2014-09-16 03:18:19 -04:00
void (*mark)(pic_state *, void *, void (*)(pic_state *, pic_value));
2014-08-25 00:38:09 -04:00
} pic_data_type;
struct pic_data {
2014-09-26 01:35:05 -04:00
PIC_OBJECT_HEADER
2014-08-25 00:38:09 -04:00
const pic_data_type *type;
2015-06-23 12:13:18 -04:00
struct pic_dict *storage;
2014-08-25 00:38:09 -04:00
void *data;
};
#define pic_data_p(o) (pic_type(o) == PIC_TT_DATA)
#define pic_data_ptr(o) ((struct pic_data *)pic_ptr(o))
2015-01-25 22:20:32 -05:00
PIC_INLINE bool pic_data_type_p(const pic_value obj, const pic_data_type *type) {
2014-08-25 00:38:09 -04:00
return pic_data_p(obj) && pic_data_ptr(obj)->type == type;
}
struct pic_data *pic_data_alloc(pic_state *, const pic_data_type *, void *);
#if defined(__cplusplus)
}
#endif
#endif