#pragma once #include #include #include [[nodiscard]] entt::id_type get_type_id(const sol::table &obj) { const auto f = obj["type_id"].get(); assert(f.valid() && "type_id not exposed to lua!"); return f.valid() ? f().get() : -1; } template [[nodiscard]] entt::id_type deduce_type(T &&obj) { switch (obj.get_type()) { // in lua: registry:has(e, Transform.type_id()) case sol::type::number: return obj.template as(); // in lua: registry:has(e, Transform) case sol::type::table: return get_type_id(obj); default: // TODO: Dont assert here. Maybe an exception could be thrown and caught by the ScriptingSystem? assert(false); return -1; } } // @see // https://github.com/skypjack/entt/wiki/Crash-Course:-runtime-reflection-system template inline auto invoke_meta_func(entt::meta_type meta_type, entt::id_type function_id, Args &&...args) { if (!meta_type) { // TODO: Warning message } else { if (auto meta_function = meta_type.func(function_id); meta_function) return meta_function.invoke({}, std::forward(args)...); } return entt::meta_any{}; } template inline auto invoke_meta_func(entt::id_type type_id, entt::id_type function_id, Args &&...args) { return invoke_meta_func(entt::resolve(type_id), function_id, std::forward(args)...); }