Skip to content

Commit

Permalink
Add full support for opaque values with ownership for unimplemented t…
Browse files Browse the repository at this point in the history
…ypes.
  • Loading branch information
viferga committed Mar 27, 2020
1 parent bf8c9dc commit 848ce46
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 70 deletions.
38 changes: 38 additions & 0 deletions source/metacall/include/metacall/metacall_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,44 @@ METACALL_API size_t metacall_value_count(void * v);
*/
METACALL_API enum metacall_value_id metacall_value_id(void * v);

/**
* @brief
* Returns the owner of the value, useful for lifecycles
*
* @param[in] v
* Reference to the value
*
* @return
* Pointer to the owner of the value,
* null means the value is not owned by anybody
*/
METACALL_API void * metacall_value_owner(void * v);

/**
* @brief
* Set up the value ownership, overwrites the previous owner
*
* @param[in] v
* Reference to the value
*
* @param[in] owner
* Reference to the new owner
*/
METACALL_API void metacall_value_own(void * v, void * owner);

/**
* @brief
* Deep copies the value @v, the result copy resets
* the reference counter and ownership
*
* @param[in] v
* Reference to the value to be copied
*
* @return
* Copy of the value @v on success, null otherwhise
*/
METACALL_API void * metacall_value_copy(void * v);

/**
* @brief
* Convert value @v to boolean
Expand Down
15 changes: 15 additions & 0 deletions source/metacall/source/metacall_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ enum metacall_value_id metacall_value_id(void * v)
return METACALL_INVALID;
}

void * metacall_value_owner(value v)
{
return value_owner(v);
}

void metacall_value_own(value v, void * owner)
{
value_own(v, owner);
}

void * metacall_value_copy(void * v)
{
return value_type_copy(v);
}

boolean metacall_value_to_bool(void * v)
{
assert(value_type_id(v) == TYPE_BOOL);
Expand Down
Loading

0 comments on commit 848ce46

Please sign in to comment.