| 3 | using namespace Nuake; |
| 4 | |
| 5 | json ModuleDB::GenerateModuleAPI() |
| 6 | { |
| 7 | json moduleAPI; |
| 8 | |
| 9 | int i = 0; |
| 10 | for (auto& [name, module] : Modules) |
| 11 | { |
| 12 | json moduleData; |
| 13 | moduleData["Name"] = name; |
| 14 | |
| 15 | auto meta = entt::resolve(entt::hashed_string(("class " + name).c_str())); |
| 16 | |
| 17 | int j = 0; |
| 18 | for (auto [id, func] : meta.func()) |
| 19 | { |
| 20 | json funcData; |
| 21 | |
| 22 | auto funcName = func.prop(HashedName::DisplayName); |
| 23 | funcData["Name"] = funcName.value().try_cast<std::string>()->c_str(); |
| 24 | funcData["ReturnType"] = func.ret().info().name(); |
| 25 | funcData["NumArgs"] = func.arity(); |
| 26 | |
| 27 | if (func.arity() > 0) |
| 28 | { |
| 29 | auto propArgsName = func.prop(HashedName::ArgsName); |
| 30 | if (propArgsName) |
| 31 | { |
| 32 | json argsData; |
| 33 | std::vector<const char*> argsName = *propArgsName.value().try_cast<std::vector<const char*>>(); |
| 34 | for (int k = 0; k < func.arity(); k++) |
| 35 | { |
| 36 | std::string argType = std::string(func.arg(k).info().name()); |
| 37 | |
| 38 | if (argType == "class Coral::String" || argType == "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >") |
| 39 | { |
| 40 | argType = "string"; |
| 41 | } |
| 42 | |
| 43 | json argData; |
| 44 | argData["Name"] = argsName[k]; |
| 45 | argData["Type"] = argType; |
| 46 | |
| 47 | argsData[k] = argData; |
| 48 | } |
| 49 | |
| 50 | funcData["Args"] = argsData; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | moduleData["Functions"][j] = funcData; |
| 55 | j++; |
| 56 | } |
| 57 | |
| 58 | moduleAPI["Modules"][i] = moduleData; |
| 59 | |
| 60 | i++; |
| 61 | } |
| 62 | |