diff --git a/Nuake/Source/Nuake/Core/Object/Object.h b/Nuake/Source/Nuake/Core/Object/Object.h index a135717a..8944cf40 100644 --- a/Nuake/Source/Nuake/Core/Object/Object.h +++ b/Nuake/Source/Nuake/Core/Object/Object.h @@ -38,6 +38,7 @@ namespace Nuake struct HashedName { NK_HASHED_STATIC_STR(DisplayName) + NK_HASHED_STATIC_STR(ArgsName) }; enum class ComponentTypeTrait : uint16_t diff --git a/Nuake/Source/Nuake/Modules/ExampleModule/ExampleModule.cpp b/Nuake/Source/Nuake/Modules/ExampleModule/ExampleModule.cpp index e547d1d5..39b7a570 100644 --- a/Nuake/Source/Nuake/Modules/ExampleModule/ExampleModule.cpp +++ b/Nuake/Source/Nuake/Modules/ExampleModule/ExampleModule.cpp @@ -39,6 +39,7 @@ class TestClass : public Class { BindField<&TestClass::Intensity>("Intensity", "Intensity"); BindProperty<&TestClass::SetIntensity, &TestClass::GetIntensity>("Intensity2", "Intensity2"); + BindFunc<&TestClass::SetIntensity>("SetIntensity", "intensity"); } public: @@ -68,7 +69,6 @@ void ExampleModule_Startup() TestClass::InternalInitializeClass(); - auto& module = ModuleDB::Get().RegisterModule(); module.instance = module.Resolve().construct(); @@ -79,43 +79,48 @@ void ExampleModule_Startup() module.BindFunction("ExampleModuleLog", "hi"); //module.Invoke("ExampleModuleLog", "Hello World"); - entt::id_type typeId = entt::hashed_string("ExampleModuleLog"); + entt::id_type typeId = entt::hashed_string(TestClass::ClassName().c_str()); entt::meta_type metaType = entt::resolve(typeId); auto resolvedFunc = metaType.func(typeId); - if (resolvedFunc) - { - resolvedFunc.invoke(module.instance, std::string("Hello has been invoked!")); - } - - Logger::Log("ExampleModule exposed API:", "Module", VERBOSE); - auto reflection = module.Resolve(); + auto reflection = metaType; for (auto [id, func] : reflection.func()) { const std::string_view returnType = func.ret().info().name(); - const std::string_view funcName = module.GetTypeName(id); - - if (funcName == "ExampleModuleLog") + auto propDisplayName = func.prop(HashedName::DisplayName); + std::string funcName = "UnknownFunc"; + if (propDisplayName) { - func.invoke(module.instance, "Hi"); + funcName = std::string(*propDisplayName.value().try_cast()); } + std::string msg = std::string(returnType) + " " + std::string(funcName) + "("; - auto argNames = module.GetFuncArgNames(id); std::vector args; - for (int i = 0; i < func.arity(); i++) - { - const std::string argType = std::string(func.arg(i).info().name()); - args.push_back(argType); - - msg += argType + " " + argNames[i]; - if (i < func.arity() - 1) + if (func.arity() > 0) + { + auto propArgsName = func.prop(HashedName::ArgsName); + if (propArgsName) { - msg += ", "; + std::vector argsName = *propArgsName.value().try_cast>(); + for (int i = 0; i < func.arity(); i++) + { + const std::string argType = std::string(func.arg(i).info().name()); + args.push_back(argType); + + msg += argType + " " + argsName[i]; + + if (i < func.arity() - 1) + { + msg += ", "; + } + } } } + + msg += ")"; Logger::Log(msg, "", VERBOSE); diff --git a/Nuake/Source/Nuake/Modules/ModuleDB.h b/Nuake/Source/Nuake/Modules/ModuleDB.h index dd22e6c2..ba2a11e2 100644 --- a/Nuake/Source/Nuake/Modules/ModuleDB.h +++ b/Nuake/Source/Nuake/Modules/ModuleDB.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include #include "Nuake/Core/Object/Object.h" @@ -42,7 +43,8 @@ public: \ return; \ \ ClassFactory.type(entt::hashed_string(#klass)); \ - ClassFactory.func<&klass::ClassName>(entt::hashed_string("ClassName")); \ + ClassFactory.func<&klass::ClassName>(entt::hashed_string("ClassName")) \ + .prop(Nuake::HashedName::DisplayName, #klass); \ if (klass::GetInitializeClass() != Class::GetInitializeClass()) \ { \ GetInitializeClass()(); \ @@ -67,14 +69,15 @@ public: \ .prop(Nuake::HashedName::DisplayName, displayName); \ } \ \ - template \ - static void BindAction(const char* funcName, const char* actionName) \ + template \ + static void BindFunc(const char* funcName, Args... args) \ { \ ClassFactory \ - .func(entt::hashed_string(funcName)) \ - .prop(Nuake::HashedName::DisplayName, actionName); \ - } - + .func(entt::hashed_string(funcName)) \ + .prop(Nuake::HashedName::DisplayName, funcName) \ + .prop(Nuake::HashedName::ArgsName, std::vector({args...})); \ + } \ + \ #define NUAKEMODULE(moduleName) \ using TypeNameMap = std::map; \