Skip to content

Commit

Permalink
meta: rebind meta_any with context(ctx)
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Feb 28, 2025
1 parent da1f56d commit e3e8449
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ TODO:
* any cdynamic to support const ownership construction
* allow passing arguments to meta setter/getter (we can fallback on meta invoke probably)
* meta: review/update rebind policy for handles and arguments
* meta: deprecate rebinding ctors for meta any/handle
10 changes: 10 additions & 0 deletions src/entt/meta/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,16 @@ class meta_any {
return *ctx;
}

/**
* @brief Returns the underlying meta context.
* @return The underlying meta context.
*/
void context(const meta_ctx &area) noexcept {
if(ctx = &area; node.resolve != nullptr) {
node = node.resolve(internal::meta_context::from(*ctx));
}
}

private:
any storage;
const meta_ctx *ctx{&locator<meta_ctx>::value_or()};
Expand Down
8 changes: 6 additions & 2 deletions test/entt/meta/meta_any.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,18 @@ TEST_F(MetaAny, Empty) {
}

TEST_F(MetaAny, Context) {
entt::meta_any any{};
using namespace entt::literals;

entt::meta_any any{std::in_place_type<clazz>};
const entt::meta_ctx ctx{};

ASSERT_TRUE(any.type().data("value"_hs));
ASSERT_EQ(&any.context(), &entt::locator<entt::meta_ctx>::value_or());
ASSERT_NE(&any.context(), &ctx);

any = entt::meta_any{entt::meta_ctx_arg, ctx};
any.context(ctx);

ASSERT_FALSE(any.type().data("value"_hs));
ASSERT_NE(&any.context(), &entt::locator<entt::meta_ctx>::value_or());
ASSERT_EQ(&any.context(), &ctx);
}
Expand Down

0 comments on commit e3e8449

Please sign in to comment.