initial
This commit is contained in:
+51
@@ -0,0 +1,51 @@
|
||||
#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{};
|
||||
ud.ctx = entt::locator<entt::meta_ctx>::handle();
|
||||
|
||||
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));
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef ENTT_LIB_META_PLUGIN_STD_USERDATA_H
|
||||
#define ENTT_LIB_META_PLUGIN_STD_USERDATA_H
|
||||
|
||||
#include <type_traits>
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
#include <entt/core/type_info.hpp>
|
||||
#include <entt/meta/context.hpp>
|
||||
#include <entt/meta/meta.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/empty.h"
|
||||
|
||||
#define ASSIGN_TYPE_ID(clazz) \
|
||||
template<> \
|
||||
struct entt::type_hash<clazz> { \
|
||||
static constexpr entt::id_type value() noexcept { \
|
||||
return entt::basic_hashed_string<std::remove_const_t<std::remove_pointer_t<std::decay_t<decltype(#clazz)>>>>{#clazz}; \
|
||||
} \
|
||||
}
|
||||
|
||||
struct userdata {
|
||||
entt::locator<entt::meta_ctx>::node_type ctx{};
|
||||
entt::meta_any any{};
|
||||
};
|
||||
|
||||
ASSIGN_TYPE_ID(void);
|
||||
ASSIGN_TYPE_ID(std::size_t);
|
||||
ASSIGN_TYPE_ID(test::boxed_int);
|
||||
ASSIGN_TYPE_ID(test::empty);
|
||||
ASSIGN_TYPE_ID(double);
|
||||
ASSIGN_TYPE_ID(int);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user