From 6286203ca5293f4a9bec536ee6af7415d8d4d8f5 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Tue, 25 Jun 2024 16:07:51 -0300 Subject: [PATCH] feat: add protocol information to native types (#247) * feat: add protocol information to native types * fix: correct typing for C String return type --- .../src/TypeScript/DefinitionWriter.cpp | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/metadata-generator/src/TypeScript/DefinitionWriter.cpp b/metadata-generator/src/TypeScript/DefinitionWriter.cpp index 6d20d891..3d8b86ab 100644 --- a/metadata-generator/src/TypeScript/DefinitionWriter.cpp +++ b/metadata-generator/src/TypeScript/DefinitionWriter.cpp @@ -883,11 +883,9 @@ std::string DefinitionWriter::tsifyType(const Type& type, const bool isFuncParam case TypeSelector: return "string"; case TypeCString: { - std::string res = "string"; - if (isFuncParam) { - Type typeVoid(TypeVoid); - res += " | " + tsifyType(::Meta::PointerType(&typeVoid), isFuncParam); - } + std::string res = isFuncParam ? "string | " : ""; + Type typeVoid(TypeVoid); + res += tsifyType(::Meta::PointerType(&typeVoid), isFuncParam); return res; } case TypeProtocol: @@ -976,7 +974,26 @@ std::string DefinitionWriter::tsifyType(const Type& type, const bool isFuncParam } } - if (interface.name == "NSArray" && isFuncParam) { + std::vector protocols; + if (type.is(TypeType::TypeInterface) && type.as().protocols.size() > 0) { + for (auto & protocol : type.as().protocols) { + if (protocol->jsName != "NSCopying") { + protocols.push_back(protocol->jsName); + } + } + } + + if (protocols.size() > 0) { + // Example: -(NSObject