add typeOf() and instanceOf()
This commit is contained in:
parent
dffbd936db
commit
6f6bb5b4e0
5 changed files with 69 additions and 10 deletions
|
|
@ -2,6 +2,7 @@ pkg = import('pkgconfig')
|
|||
|
||||
librtti_c_srcs=[
|
||||
'create.c',
|
||||
'typeinfo.c',
|
||||
'lock.c',
|
||||
'iter.c',
|
||||
'ref.c',
|
||||
|
|
|
|||
27
src/typeinfo.c
Normal file
27
src/typeinfo.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "rtti.h"
|
||||
|
||||
typeinfo_t *typeOf(var v) {
|
||||
meta_obj_t *obj = NULL;
|
||||
|
||||
obj = RTTI_DATA_TO_OBJ(v);
|
||||
if (RTTI_OBJ_INVALID(obj)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return obj->type;
|
||||
}
|
||||
|
||||
int instanceOf(var v, typeinfo_t *t) {
|
||||
if ((v == NULL) || (t == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (typeOf(v) == t) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue