Skip to content

Commit

Permalink
Assorted fixes from the editor work
Browse files Browse the repository at this point in the history
  • Loading branch information
migueldeicaza committed Sep 21, 2023
1 parent ef01573 commit 651645e
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 12 deletions.
4 changes: 3 additions & 1 deletion Generator/Generator/BuiltinGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,9 @@ func generateBuiltinClasses (values: [JGodotBuiltinClass], outputDir: String) {
}

p ("deinit"){
p ("\(typeName).destructor (&content)")
p ("if content != \(typeName).zero") {
p ("\(typeName).destructor (&content)")
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion Generator/Generator/ClassGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func makeDefaultInit (godotType: String, initCollection: String = "") -> String

case let other where builtinGodotTypeNames [other] != nil:
return "\(godotType) ()"
case "void*":
case "void*", "const Glyph*":
return "nil"
default:
if isCoreType(name: godotType) {
Expand Down Expand Up @@ -149,6 +149,8 @@ func generateVirtualProxy (_ p: Printer,
p ("retPtr!.storeBytes (of: ret, as: \(virtRet!).self)")
} else if ret.type.starts(with: "enum::") {
p ("retPtr!.storeBytes (of: Int32 (ret.rawValue), as: Int32.self)")
} else if ret.type.contains("*") {
p ("retPtr!.storeBytes (of: ret, as: OpaquePointer?.self)")
} else {
let derefField: String
let derefType: String
Expand Down Expand Up @@ -629,6 +631,9 @@ func processClass (cdef: JGodotExtensionAPIClass, outputDir: String) {
p ("/// Ths initializer is invoked by derived classes as they chain through their most derived type name that our framework produced")
p ("internal override init (name: StringName)") {
p("super.init (name: name)")
if (cdef.name == "RefCounted") {
p ("reference ()")
}
}

let fastInitOverrides = cdef.inherits != nil ? "override " : ""
Expand Down
8 changes: 4 additions & 4 deletions Generator/Generator/MethodGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ func methodGen (_ p: Printer, method: MethodDefinition, className: String, cdef:
//print ("TODO: do not currently have support for C pointer types \(loc)")
return nil
}
if method.returnValue?.type.firstIndex(of: "*") != nil {
//print ("TODO: do not currently support C pointer returns \(loc)")
return nil
}
// if method.returnValue?.type.firstIndex(of: "*") != nil {
// //print ("TODO: do not currently support C pointer returns \(loc)")
// return nil
// }
let bindName = "method_\(method.name)"

var visibility: String
Expand Down
2 changes: 2 additions & 0 deletions Generator/Generator/TypeHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ func getGodotType (_ t: TypeWithMeta?, kind: ArgumentKind = .classes) -> String
return "GArray"
case "void*":
return "OpaquePointer?"
case "const Glyph*":
return "OpaquePointer?"
case "Type":
return "GType"
default:
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PackageDescription
let package = Package(
name: "SwiftGodot",
platforms: [
.macOS(.v10_15),
.macOS(.v13),
.iOS ("16.0")
],
products: [
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftGodot/Core/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
@_implementationOnly import GDExtension

extension StringName {
extension StringName: CustomStringConvertible {
/// Creates a StringName from a Swift String
public convenience init (_ from: String) {
self.init (from: from)
Expand Down Expand Up @@ -43,7 +43,7 @@ func stringFromGodotString (_ ptr: UnsafeRawPointer) -> String? {
}
}

extension GString {
extension GString: CustomStringConvertible {
/// Returns a Swift string from a pointer to a native Godot string
static func stringFromGStringPtr (ptr: UnsafeRawPointer?) -> String? {
guard let ptr else {
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftGodot/Core/Wrapped.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ open class Wrapped: Equatable, Identifiable, Hashable {
}

class func getVirtualDispatcher(name: StringName) -> GDExtensionClassCallVirtual? {
print ("SWARN: getVirtualDispatcher (\"\(name)\") reached Wrapped on class \(self)")
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftGodot/Variant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ public class Variant: Hashable, Equatable, ExpressibleByStringLiteral {
}

public init (_ value: String) {
var vh: UnsafeMutableRawPointer?
var v = GDExtensionStringPtr (mutating: value.cString(using: .utf8))
Variant.fromTypeMap [GType.string.rawValue] (&content, &v)
var gstring = GString (stringLiteral: value)

Variant.fromTypeMap [GType.string.rawValue] (&content, &gstring.content)
}

public required init(stringLiteral: String) {
Expand Down

0 comments on commit 651645e

Please sign in to comment.