fx: object: add clone() virtual function

This commit is contained in:
2026-07-05 15:58:50 +01:00
parent c29c687076
commit 38699a0eb3
2 changed files with 19 additions and 0 deletions
+2
View File
@@ -22,6 +22,7 @@ typedef struct _fx_object_class {
FX_TYPE_FWDREF(fx_stream) *, FX_TYPE_FWDREF(fx_stream) *,
const char *); const char *);
fx_status (*hash)(const struct fx_value *, uint64_t *); fx_status (*hash)(const struct fx_value *, uint64_t *);
fx_status (*clone)(const struct fx_value *, struct fx_value *);
} fx_object_class; } fx_object_class;
FX_API fx_type_id fx_object_get_type(void); 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, const fx_object *p,
FX_TYPE_FWDREF(fx_stream) * out, FX_TYPE_FWDREF(fx_stream) * out,
const char *format); 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); FX_API bool fx_object_is_type(const fx_object *p, fx_type_id type);
#endif #endif
+17
View File
@@ -98,6 +98,23 @@ fx_status fx_object_to_string(
return FX_SUCCESS; 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) bool fx_object_is_type(const struct _fx_object *p, fx_type_id type)
{ {
if (!p) { if (!p) {