diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-03-04 15:52:53 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-03-08 17:15:16 +0100 |
commit | 37d5e35437df393cd23e90f72579dea8d91fdea0 (patch) | |
tree | 4de53d110c5ac5e644bcc2beddd47ec1d7f8c91c | |
parent | c6081c912b2f0f656c90237c9439bf1366f1d18b (diff) |
object: introduce uc_protoref_new()
The new uc_protoref_new() function allows creating array or object values
with prototype references.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | object.c | 23 | ||||
-rw-r--r-- | object.h | 1 |
2 files changed, 24 insertions, 0 deletions
@@ -316,6 +316,29 @@ uc_prototype_new(uc_prototype *parent) return proto; } +uc_prototype * +uc_protoref_new(json_object *value, uc_prototype *proto) +{ + uc_prototype *ref; + + if (!json_object_is_type(value, json_type_object) && + !json_object_is_type(value, json_type_array)) + return NULL; + + ref = xalloc(sizeof(*ref)); + ref->header.type = UC_OBJ_PROTOTYPE; + ref->header.jso = value; + + if (proto) { + ref->parent = proto; + uc_value_get(proto->header.jso); + } + + json_object_set_serializer(ref->header.jso, NULL, ref, uc_prototype_gc); + + return ref; +} + static uc_ressource_types res_types; @@ -118,6 +118,7 @@ uc_closure *uc_closure_new(uc_function *function, bool arrow_fn); 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); 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); |