add user-defined data type API

This commit is contained in:
Yuichi Nishiwaki
2014-03-29 20:42:06 +09:00
parent 1813ba2d6f
commit d8c182bc69
7 changed files with 74 additions and 1 deletions
+33
View File
@@ -0,0 +1,33 @@
/**
* See Copyright Notice in picrin.h
*/
#ifndef PICRIN_DATA_H__
#define PICRIN_DATA_H__
#if defined(__cplusplus)
extern "C" {
#endif
typedef struct {
const char *type_name;
void (*dtor)(pic_state *, void *);
} pic_data_type;
struct pic_data {
PIC_OBJECT_HEADER;
const pic_data_type *type;
xhash storage; /* const char * to pic_value table */
void *data;
};
#define pic_data_p(o) (pic_type(o) == PIC_TT_DATA)
#define pic_data_ptr(o) ((struct pic_data *)pic_ptr(o))
struct pic_data *pic_data_alloc(pic_state *, const pic_data_type *, void *);
#if defined(__cplusplus)
}
#endif
#endif
+4 -1
View File
@@ -114,7 +114,8 @@ enum pic_tt {
PIC_TT_SC,
PIC_TT_LIB,
PIC_TT_VAR,
PIC_TT_IREP
PIC_TT_IREP,
PIC_TT_DATA
};
#define PIC_OBJECT_HEADER \
@@ -258,6 +259,8 @@ pic_type_repr(enum pic_tt tt)
return "var";
case PIC_TT_IREP:
return "irep";
case PIC_TT_DATA:
return "data";
}
return 0; /* logic flaw */
}