Mercurial > repos > tabletprog
comparison runtime/object.c @ 266:75dc7161c1ca
Added object module which provides some basic reflection capabilities
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 17 Jul 2014 23:57:41 -0700 |
parents | abc6f3d644a4 |
children | d2b70cba661e |
comparison
equal
deleted
inserted
replaced
265:d6a4c9e7716e | 266:75dc7161c1ca |
---|---|
8 { | 8 { |
9 va_list args; | 9 va_list args; |
10 object * newobj = GC_MALLOC(meta->size); | 10 object * newobj = GC_MALLOC(meta->size); |
11 newobj->meta = meta; | 11 newobj->meta = meta; |
12 newobj->parent = parent; | 12 newobj->parent = parent; |
13 | 13 |
14 va_start(args, num_props); | 14 va_start(args, num_props); |
15 object ** curprop = ((object **)(newobj + 1)); | 15 object ** curprop = ((object **)(newobj + 1)); |
16 for (; num_props > 0; num_props--) | 16 for (; num_props > 0; num_props--) |
17 { | 17 { |
18 *curprop = va_arg(args, object *); | 18 *curprop = va_arg(args, object *); |
28 va_start(args, self); | 28 va_start(args, self); |
29 object * ret = self->meta->meth_lookup[method_id & 0xF](method_id, num_args, self, args); | 29 object * ret = self->meta->meth_lookup[method_id & 0xF](method_id, num_args, self, args); |
30 va_end(args); | 30 va_end(args); |
31 return ret; | 31 return ret; |
32 } | 32 } |
33 | |
34 int object_understands(object * obj, uint32_t method_id) | |
35 { | |
36 uint32_t slot = method_id & 0xF; | |
37 uint32_t *cur; | |
38 if (!obj->meta->methods[slot]) { | |
39 return 0; | |
40 } | |
41 for (cur = obj->meta->methods[slot]; *cur != LAST_METHOD; cur++) { | |
42 if (*cur == method_id) { | |
43 return 1; | |
44 } | |
45 } | |
46 return 0; | |
47 } |