From f9c8efb9b187afe8869ce4dd243b232b763f7df0 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 23 Oct 2021 14:12:22 +0200 Subject: [PATCH] Adds support for astypedef exports. --- CMakeLists.txt | 2 +- CMakeLists.txt.in | 7 +- conanfile.py | 19 ----- src/Tools/ScriptHeadersExporter.cpp | 122 ++++++++++++++++++++++++++-- 4 files changed, 119 insertions(+), 31 deletions(-) delete mode 100644 conanfile.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e16358..3232307 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,4 +14,4 @@ add_definitions(-DLEVEL_U8) SET(_LINKS Arbutils CreatureLib pkmnLib) target_link_libraries(PkmnLibTools PUBLIC ${_LINKS}) -target_compile_options(PkmnLibTools PRIVATE -Wall -Wextra -Werror) +target_compile_options(PkmnLibTools PRIVATE -Wall -Wextra -Werror) \ No newline at end of file diff --git a/CMakeLists.txt.in b/CMakeLists.txt.in index d3867f1..dad6d68 100644 --- a/CMakeLists.txt.in +++ b/CMakeLists.txt.in @@ -42,9 +42,10 @@ function(include_pkmnlib) ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/include/PkmnLib) include_directories(${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/include - ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/CreatureLib/include - ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/Angelscript/src/AngelscriptProj/angelscript/include - ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/CreatureLib/bin/Arbutils/include) + ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/src/pkmnlib/extern/AngelscriptDebuggerServer/extern/asio-1.18.2/include + ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/CreatureLib/include + ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/Angelscript/src/AngelscriptProj/angelscript/include + ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/CreatureLib/bin/Arbutils/include) endfunction() \ No newline at end of file diff --git a/conanfile.py b/conanfile.py deleted file mode 100644 index 9e977de..0000000 --- a/conanfile.py +++ /dev/null @@ -1,19 +0,0 @@ -from conans import ConanFile, CMake -from conans.errors import ConanInvalidConfiguration - - -class PkmnLibConan(ConanFile): - name = "PkmnLibTools" - license = "TODO" - url = "https://git.p-epsilon.com/Deukhoofd/PkmnLib" - description = "" - settings = "os", "compiler", "build_type" - generators = "cmake" - exports_sources = "*" - compiler = "clang" - - def requirements(self): - self.requires("Arbutils/latest@epsilon/master") - self.requires("CreatureLib/latest@epsilon/master") - self.requires("PkmnLib/latest@epsilon/master") - self.requires("AngelScript/2.35@AngelScript/Deukhoofd") diff --git a/src/Tools/ScriptHeadersExporter.cpp b/src/Tools/ScriptHeadersExporter.cpp index 27ab8fc..cef41fa 100644 --- a/src/Tools/ScriptHeadersExporter.cpp +++ b/src/Tools/ScriptHeadersExporter.cpp @@ -10,7 +10,83 @@ static bool replace(std::string& str, const std::string& from, const std::string return true; } -static void PrintObjectType(asITypeInfo* type, const std::filesystem::path& dir){ +static void PrintObjectTypeDef(asITypeInfo* type, const std::filesystem::path& dir) { + auto name = std::string(type->GetName()); + if (name == "string" || name == "array") + return; + + std::fstream fs; + fs.open((dir / name).concat(".astypedef"), std::fstream::out); + + if ((type->GetFlags() & asOBJ_VALUE) != 0 && (type->GetFlags() & asOBJ_ASHANDLE) == 0){ + fs << "valuetype"; + } + else{ + fs << "type"; + } + + fs << " " << type->GetName(); + if ((type->GetFlags() & asOBJ_TEMPLATE) != 0) { + fs << "<"; + for (asUINT i = 0; i < type->GetSubTypeCount(); ++i) { + if (i != 0) { + fs << ", "; + } + fs << type->GetSubType(i)->GetName(); + } + fs << ">"; + } + fs << " {" << std::endl; + + auto behaviourCount = type->GetBehaviourCount(); + for (asUINT j = 0; j < behaviourCount; j++) { + if (name == "ref") + break; + if (name == "dictionaryValue") + break; + asEBehaviours behaviourType; + auto behaviour = type->GetBehaviourByIndex(j, &behaviourType); + if (behaviourType > 4) { + continue; + } + auto decl = std::string(behaviour->GetDeclaration(false, false, true)); + if (behaviourType == asBEHAVE_CONSTRUCT || behaviourType == asBEHAVE_FACTORY) { + replace(decl, type->GetName(), "void f"); + } + if (behaviourType == asBEHAVE_DESTRUCT) { + replace(decl, std::string("~") + type->GetName(), "void f"); + } + if (behaviourType == asBEHAVE_LIST_CONSTRUCT || behaviourType == asBEHAVE_LIST_FACTORY) { + replace(decl, "$list", "f"); + } + fs << " behave " << behaviourType << " " << decl << ";" << std::endl; + } + auto propertyCount = type->GetMethodCount(); + for (asUINT j = 0; j < propertyCount; j++) { + auto method = type->GetMethodByIndex(j); + if (method->IsProperty()) { + auto name = std::string(method->GetName()); + auto decl = std::string(method->GetDeclaration(false, true, false)); + auto realName = name.substr(4); + replace(decl, name, realName); + replace(decl, "() const", " { get const; }"); + replace(decl, "()", " { get; }"); + + fs << " " << decl << ";" << std::endl; + } else { + auto name = std::string(method->GetName()); + auto decl = std::string(method->GetDeclaration(false, true, true)); + replace(decl, "&in", " &in"); + replace(decl, "&out", " &out"); + replace(decl, "ref", "ref@"); + fs << " " << decl << ";" << std::endl; + } + } + fs << "}" << std::endl; + fs.close(); +} + +static void PrintScriptObject(asITypeInfo* type, const std::filesystem::path& dir) { auto name = std::string(type->GetName()); if (name == "string" || name == "array" || name == "ref") return; @@ -45,8 +121,19 @@ static void PrintObjectType(asITypeInfo* type, const std::filesystem::path& dir) replace(decl, "&in", " &in"); replace(decl, "&out", " &out"); fs << "\t" << decl; - if (isAbstract) - fs << "{};" << std::endl; + if (isAbstract){ + if (method->GetReturnTypeId() == 0){ + fs << "{};" << std::endl; + } + else{ + if (method->GetReturnTypeId() == asTYPEID_BOOL){ + fs << "{ return false; };" << std::endl; + } + else{ + fs << "{ return 0; };" << std::endl; + } + } + } else fs << ";" << std::endl; } @@ -65,23 +152,30 @@ void ScriptHeadersExporter::Export(const std::string& outPath) { std::filesystem::path dir(outPath); for (asUINT i = 0; i < typesCount; i++) { auto type = engine->GetObjectTypeByIndex(i); - PrintObjectType(type, dir); + if ((type->GetTypeId() & asTYPEID_SCRIPTOBJECT) != 0) { + PrintScriptObject(type, dir); + } else { + PrintObjectTypeDef(type, dir); + } } auto moduleTypesCount = module->GetObjectTypeCount(); for (asUINT i = 0; i < moduleTypesCount; i++) { auto type = module->GetObjectTypeByIndex(i); - PrintObjectType(type, dir); + if ((type->GetTypeId() & asTYPEID_SCRIPTOBJECT) != 0) { + PrintScriptObject(type, dir); + } else { + PrintObjectTypeDef(type, dir); + } } - auto enumCount = engine->GetEnumCount(); for (asUINT i = 0; i < enumCount; i++) { auto en = engine->GetEnumByIndex(i); auto name = en->GetName(); std::fstream fs; - fs.open((dir / name).concat(".as"), std::fstream::out); + fs.open((dir / name).concat(".astypedef"), std::fstream::out); - fs << "shared enum " << en->GetName() << " {" << std::endl; + fs << "enum " << en->GetName() << " {" << std::endl; auto valueCount = en->GetEnumValueCount(); for (asUINT j = 0; j < valueCount; j++) { int val; @@ -91,4 +185,16 @@ void ScriptHeadersExporter::Export(const std::string& outPath) { fs << "}" << std::endl; fs.close(); } + + auto globalFuncs = engine->GetGlobalFunctionCount(); + if (globalFuncs > 0){ + std::fstream fs; + fs.open((dir / "globals").concat(".astypedef"), std::fstream::out); + + for (asUINT i = 0; i < globalFuncs; ++i) { + auto func = engine->GetGlobalFunctionByIndex(i); + fs << "func " << func->GetDeclaration(false, false, true) << ";" << std::endl; + } + } + } \ No newline at end of file