Mercurial > repos > tabletprog
diff 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 |
line wrap: on
line diff
--- a/runtime/object.c Mon Jul 14 19:03:46 2014 -0700 +++ b/runtime/object.c Thu Jul 17 23:57:41 2014 -0700 @@ -10,7 +10,7 @@ object * newobj = GC_MALLOC(meta->size); newobj->meta = meta; newobj->parent = parent; - + va_start(args, num_props); object ** curprop = ((object **)(newobj + 1)); for (; num_props > 0; num_props--) @@ -30,3 +30,18 @@ va_end(args); return ret; } + +int object_understands(object * obj, uint32_t method_id) +{ + uint32_t slot = method_id & 0xF; + uint32_t *cur; + if (!obj->meta->methods[slot]) { + return 0; + } + for (cur = obj->meta->methods[slot]; *cur != LAST_METHOD; cur++) { + if (*cur == method_id) { + return 1; + } + } + return 0; +}