This commit is contained in:
Martin Slachta
2026-07-18 14:31:15 +02:00
commit a04f0dc262
3343 changed files with 1140208 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
#define CR_HOST
#include <gtest/gtest.h>
#include <cr.h>
#include <entt/core/hashed_string.hpp>
#include <entt/locator/locator.hpp>
#include <entt/meta/context.hpp>
#include <entt/meta/meta.hpp>
#include <entt/meta/resolve.hpp>
#include "userdata.h"
TEST(Lib, Meta) {
using namespace entt::literals;
ASSERT_FALSE(entt::resolve("boxed_int"_hs));
userdata ud{entt::locator<entt::meta_ctx>::handle(), entt::meta_any{}};
cr_plugin ctx;
ctx.userdata = &ud;
cr_plugin_load(ctx, PLUGIN);
cr_plugin_update(ctx);
ASSERT_TRUE(entt::resolve("boxed_int"_hs));
ASSERT_TRUE(entt::resolve("empty"_hs));
auto boxed_int = entt::resolve("boxed_int"_hs).construct(4.);
auto empty = entt::resolve("empty"_hs).construct();
ASSERT_TRUE(boxed_int);
ASSERT_TRUE(empty);
ASSERT_EQ(boxed_int.type().data("value"_hs).type(), entt::resolve<int>());
ASSERT_NE(boxed_int.get("value"_hs).try_cast<int>(), nullptr);
ASSERT_EQ(boxed_int.get("value"_hs).cast<int>(), 4);
ASSERT_EQ(ud.any.type(), entt::resolve<int>());
ASSERT_EQ(ud.any.cast<int>(), 4);
// these objects have been initialized from a different context
boxed_int.emplace<void>();
empty.emplace<void>();
ud.any.emplace<void>();
cr_plugin_close(ctx);
ASSERT_FALSE(entt::resolve("boxed_int"_hs));
ASSERT_FALSE(entt::resolve("empty"_hs));
}
+49
View File
@@ -0,0 +1,49 @@
#include <cr.h>
#include <entt/core/hashed_string.hpp>
#include <entt/locator/locator.hpp>
#include <entt/meta/context.hpp>
#include <entt/meta/factory.hpp>
#include <entt/meta/meta.hpp>
#include "../../../common/boxed_type.h"
#include "../../../common/empty.h"
#include "userdata.h"
test::boxed_int create_boxed_int(int value) {
return test::boxed_int{value};
}
void set_up() {
using namespace entt::literals;
entt::meta_factory<test::boxed_int>{}
.type("boxed_int"_hs)
.ctor<&create_boxed_int>()
.data<&test::boxed_int::value>("value"_hs);
entt::meta_factory<test::empty>{}
.type("empty"_hs)
.ctor<>();
}
void tear_down() {
entt::meta_reset<test::boxed_int>();
entt::meta_reset<test::empty>();
}
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
switch(operation) {
case CR_LOAD:
entt::locator<entt::meta_ctx>::reset(static_cast<userdata *>(ctx->userdata)->ctx);
set_up();
break;
case CR_STEP:
static_cast<userdata *>(ctx->userdata)->any = 4;
break;
case CR_UNLOAD:
case CR_CLOSE:
tear_down();
break;
}
return 0;
}
+13
View File
@@ -0,0 +1,13 @@
#ifndef ENTT_LIB_META_PLUGIN_USERDATA_H
#define ENTT_LIB_META_PLUGIN_USERDATA_H
#include <entt/locator/locator.hpp>
#include <entt/meta/context.hpp>
#include <entt/meta/meta.hpp>
struct userdata {
entt::locator<entt::meta_ctx>::node_type ctx{};
entt::meta_any any{};
};
#endif