diff --git a/fx/include/fx/object.h b/fx/include/fx/object.h index 703ed0e..3144f6a 100644 --- a/fx/include/fx/object.h +++ b/fx/include/fx/object.h @@ -22,6 +22,7 @@ typedef struct _fx_object_class { FX_TYPE_FWDREF(fx_stream) *, const char *); fx_status (*hash)(const struct fx_value *, uint64_t *); + fx_status (*clone)(const struct fx_value *, struct fx_value *); } fx_object_class; FX_API fx_type_id fx_object_get_type(void); @@ -46,6 +47,7 @@ FX_API fx_status fx_object_to_string( const fx_object *p, FX_TYPE_FWDREF(fx_stream) * out, const char *format); +FX_API fx_status fx_object_clone(const fx_object *src, fx_object **dest); FX_API bool fx_object_is_type(const fx_object *p, fx_type_id type); #endif diff --git a/fx/object.c b/fx/object.c index 8aa8631..fd9cc25 100644 --- a/fx/object.c +++ b/fx/object.c @@ -98,6 +98,23 @@ fx_status fx_object_to_string( return FX_SUCCESS; } +fx_status fx_object_clone(const fx_object *src, fx_object **dest) +{ + fx_object_class *iface = fx_object_get_interface(src, FX_TYPE_OBJECT); + fx_value dest_v = FX_VALUE_EMPTY; + if (!iface || !iface->clone) { + return FX_ERR_NOT_SUPPORTED; + } + + fx_status status = iface->clone(&FX_VALUE_OBJECT(src), &dest_v); + if (!FX_OK(status)) { + return status; + } + + fx_value_get_object(&dest_v, dest); + return status; +} + bool fx_object_is_type(const struct _fx_object *p, fx_type_id type) { if (!p) {