summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-03-08 17:08:33 +0100
committerJo-Philipp Wich <jo@mein.io>2021-03-08 19:18:58 +0100
commitcef905b811b5e557e4aea01ccf76a7cddebd6d04 (patch)
treef5d813ca75e62a5de717a44b656e0540f215fb62
parentd02d1a304f709e66edb9443ec2a4aff09dca1c0b (diff)
object: introduce uc_prototype_lookup()
The new uc_prototype_lookup() function allows looking up properties in the given prototype chain. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--object.c12
-rw-r--r--object.h1
2 files changed, 13 insertions, 0 deletions
diff --git a/object.c b/object.c
index 4e49ac4..c0a5227 100644
--- a/object.c
+++ b/object.c
@@ -316,6 +316,18 @@ uc_prototype_new(uc_prototype *parent)
return proto;
}
+json_object *
+uc_prototype_lookup(uc_prototype *proto, const char *key)
+{
+ json_object *val;
+
+ for (; proto; proto = proto->parent)
+ if (json_object_object_get_ex(proto->header.jso, key, &val))
+ return val;
+
+ return NULL;
+}
+
uc_prototype *
uc_protoref_new(json_object *value, uc_prototype *proto)
{
diff --git a/object.h b/object.h
index 069f9ed..7ceb521 100644
--- a/object.h
+++ b/object.h
@@ -119,6 +119,7 @@ uc_cfunction *uc_cfunction_new(const char *name, uc_cfn_ptr cfn);
uc_regexp *uc_regexp_new(const char *pattern, bool icase, bool newline, bool global, char **err);
uc_prototype *uc_prototype_new(uc_prototype *parent);
uc_prototype *uc_protoref_new(json_object *value, uc_prototype *proto);
+json_object *uc_prototype_lookup(uc_prototype *proto, const char *key);
uc_ressource_type *uc_ressource_type_add(const char *name, uc_prototype *proto, void (*freefn)(void *));
uc_ressource_type *uc_ressource_type_lookup(const char *name);