diff --git a/Generator/Generator/StringOperations.swift b/Generator/Generator/StringOperations.swift index 53a3075c4..d42e3d2a9 100644 --- a/Generator/Generator/StringOperations.swift +++ b/Generator/Generator/StringOperations.swift @@ -88,7 +88,18 @@ extension String { func dropPrefix(_ prefix: String) -> String { guard hasPrefix(prefix) else { return self } guard prefix != self else { return self } - let suffix = String(dropFirst(prefix.count)) + let prefixSize: Int + // special-case for https://github.com/migueldeicaza/SwiftGodot/issues/23 + if prefix == "METHOD_", contains("METHOD_FLAG") { + if self == "METHOD_FLAGS_DEFAULT" { + prefixSize = "METHOD_FLAGS_".count + } else { + prefixSize = "METHOD_FLAG_".count + } + } else { + prefixSize = prefix.count + } + let suffix = String(dropFirst(prefixSize)) return suffix.isValidSwiftName() ? suffix : self } diff --git a/Sources/SimpleExtension/Demo.swift b/Sources/SimpleExtension/Demo.swift index 121e63136..c37871bac 100644 --- a/Sources/SimpleExtension/Demo.swift +++ b/Sources/SimpleExtension/Demo.swift @@ -91,8 +91,8 @@ class SwiftSprite2: Sprite2D { hintStr: "Some kind of food", usage: .default) ] - classInfo.registerMethod(name: "demo_set_favorite_food", flags: .flagsDefault, returnValue: nil, arguments: foodArgs, function: SwiftSprite2.demoSetFavoriteFood) - classInfo.registerMethod(name: "demo_get_favorite_food", flags: .flagsDefault, returnValue: foodArgs [0], arguments: [], function: SwiftSprite2.demoGetFavoriteFood) + classInfo.registerMethod(name: "demo_set_favorite_food", flags: .default, returnValue: nil, arguments: foodArgs, function: SwiftSprite2.demoSetFavoriteFood) + classInfo.registerMethod(name: "demo_get_favorite_food", flags: .default, returnValue: foodArgs [0], arguments: [], function: SwiftSprite2.demoGetFavoriteFood) let foodProp = PropInfo (propertyType: .string, propertyName: "demo_favorite_food", diff --git a/Sources/SwiftGodot/Core/SignalSupport.swift b/Sources/SwiftGodot/Core/SignalSupport.swift index 044f1b6f9..b6e558e30 100644 --- a/Sources/SwiftGodot/Core/SignalSupport.swift +++ b/Sources/SwiftGodot/Core/SignalSupport.swift @@ -24,7 +24,7 @@ public class SignalProxy: Object { let s = ClassInfo(name: "SignalProxy") - s.registerMethod(name: SignalProxy.proxyName, flags: .flagsDefault, returnValue: nil, arguments: [], function: SignalProxy.proxyFunc) + s.registerMethod(name: SignalProxy.proxyName, flags: .default, returnValue: nil, arguments: [], function: SignalProxy.proxyFunc) return true } () diff --git a/Sources/SwiftGodot/Extensions/ClassInfo+ConvenienceProperties.swift b/Sources/SwiftGodot/Extensions/ClassInfo+ConvenienceProperties.swift index b05999eab..a8e6b52f5 100644 --- a/Sources/SwiftGodot/Extensions/ClassInfo+ConvenienceProperties.swift +++ b/Sources/SwiftGodot/Extensions/ClassInfo+ConvenienceProperties.swift @@ -250,7 +250,7 @@ extension ClassInfo { private func registerGetter(prefix: String, name: String, property: PropInfo, getter: @escaping ClassInfoFunction) { registerMethod(name: StringName("\(prefix)_get_\(name)"), - flags: .flagsDefault, + flags: .default, returnValue: property, arguments: [], function: getter) @@ -258,7 +258,7 @@ extension ClassInfo { private func registerSetter(prefix: String, name: String, property: PropInfo, setter: @escaping ClassInfoFunction) { registerMethod(name: StringName("\(prefix)_set_\(name)"), - flags: .flagsDefault, + flags: .default, returnValue: nil, arguments: [property], function: setter) diff --git a/Sources/SwiftGodotMacroLibrary/MacroGodot.swift b/Sources/SwiftGodotMacroLibrary/MacroGodot.swift index c1b1abe7d..3b25b5639 100644 --- a/Sources/SwiftGodotMacroLibrary/MacroGodot.swift +++ b/Sources/SwiftGodotMacroLibrary/MacroGodot.swift @@ -68,7 +68,7 @@ class GodotMacroProcessor { funcArgs.append ("\t]\n") } ctor.append (funcArgs) - ctor.append ("\tclassInfo.registerMethod(name: StringName(\"\(funcName)\"), flags: .flagsDefault, returnValue: \(retProp ?? "nil"), arguments: \(funcArgs == "" ? "[]" : "\(funcName)Args"), function: \(className)._mproxy_\(funcName))") + ctor.append ("\tclassInfo.registerMethod(name: StringName(\"\(funcName)\"), flags: .default, returnValue: \(retProp ?? "nil"), arguments: \(funcArgs == "" ? "[]" : "\(funcName)Args"), function: \(className)._mproxy_\(funcName))") } func processVariable (_ varDecl: VariableDeclSyntax) throws { @@ -151,8 +151,8 @@ class GodotMacroProcessor { """) - ctor.append("\tclassInfo.registerMethod (name: \"\(getterName)\", flags: .flagsDefault, returnValue: \(pinfo), arguments: [], function: \(className).\(getterName))\n") - ctor.append("\tclassInfo.registerMethod (name: \"\(setterName)\", flags: .flagsDefault, returnValue: nil, arguments: [\(pinfo)], function: \(className).\(setterName))\n") + ctor.append("\tclassInfo.registerMethod (name: \"\(getterName)\", flags: .default, returnValue: \(pinfo), arguments: [], function: \(className).\(getterName))\n") + ctor.append("\tclassInfo.registerMethod (name: \"\(setterName)\", flags: .default, returnValue: nil, arguments: [\(pinfo)], function: \(className).\(setterName))\n") ctor.append("\tclassInfo.registerProperty (\(pinfo), getter: \"\(getterName)\", setter: \"\(setterName)\")") } } diff --git a/Tests/SwiftGodotMacrosTests/MacroGodotTests.swift b/Tests/SwiftGodotMacrosTests/MacroGodotTests.swift index 6757a1490..e02737cdd 100644 --- a/Tests/SwiftGodotMacrosTests/MacroGodotTests.swift +++ b/Tests/SwiftGodotMacrosTests/MacroGodotTests.swift @@ -115,7 +115,7 @@ final class MacroGodotTests: XCTestCase { static var _initClass: Void = { let className = StringName("Castro") let classInfo = ClassInfo (name: className) - classInfo.registerMethod(name: StringName("deleteEpisode"), flags: .flagsDefault, returnValue: nil, arguments: [], function: Castro._mproxy_deleteEpisode) + classInfo.registerMethod(name: StringName("deleteEpisode"), flags: .default, returnValue: nil, arguments: [], function: Castro._mproxy_deleteEpisode) } () } """, @@ -162,8 +162,8 @@ final class MacroGodotTests: XCTestCase { hint: .none, hintStr: "", usage: .default) - classInfo.registerMethod (name: "_mproxy_get_goodName", flags: .flagsDefault, returnValue: _pgoodName, arguments: [], function: Hi._mproxy_get_goodName) - classInfo.registerMethod (name: "_mproxy_set_goodName", flags: .flagsDefault, returnValue: nil, arguments: [_pgoodName], function: Hi._mproxy_set_goodName) + classInfo.registerMethod (name: "_mproxy_get_goodName", flags: .default, returnValue: _pgoodName, arguments: [], function: Hi._mproxy_get_goodName) + classInfo.registerMethod (name: "_mproxy_set_goodName", flags: .default, returnValue: nil, arguments: [_pgoodName], function: Hi._mproxy_set_goodName) classInfo.registerProperty (_pgoodName, getter: "_mproxy_get_goodName", setter: "_mproxy_set_goodName") } () }