meta: allow updating values on meta properties
This commit is contained in:
@@ -763,6 +763,14 @@ struct meta_prop {
|
||||
return node->value ? node->type(internal::meta_context::from(*ctx)).from_void(*ctx, nullptr, node->value.get()) : meta_any{meta_ctx_arg, *ctx};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the stored value by reference.
|
||||
* @return A wrapper containing the value stored with the property.
|
||||
*/
|
||||
[[nodiscard]] meta_any value() {
|
||||
return node->value ? node->type(internal::meta_context::from(*ctx)).from_void(*ctx, node->value.get(), nullptr) : meta_any{meta_ctx_arg, *ctx};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns true if an object is valid, false otherwise.
|
||||
* @return True if the object is valid, false otherwise.
|
||||
|
||||
@@ -49,7 +49,18 @@ TEST_F(MetaProp, Functionalities) {
|
||||
auto prop = entt::resolve<base_1_t>().prop("int"_hs);
|
||||
|
||||
ASSERT_TRUE(prop);
|
||||
ASSERT_EQ(prop.value(), 42);
|
||||
|
||||
auto value = prop.value();
|
||||
auto cvalue = std::as_const(prop).value();
|
||||
|
||||
ASSERT_NE(value.try_cast<int>(), nullptr);
|
||||
ASSERT_EQ(cvalue.try_cast<int>(), nullptr);
|
||||
|
||||
ASSERT_NE(value.try_cast<const int>(), nullptr);
|
||||
ASSERT_NE(cvalue.try_cast<const int>(), nullptr);
|
||||
|
||||
ASSERT_EQ(value, 42);
|
||||
ASSERT_EQ(cvalue, 42);
|
||||
}
|
||||
|
||||
TEST_F(MetaProp, FromBase) {
|
||||
|
||||
Reference in New Issue
Block a user