Closed elijah-semyonov closed 1 week ago
The Windows build is breaking due to a change in Arguments:
2024-11-06T11:23:04.8173115Z D:\a\SwiftGodot\SwiftGodot\Sources\SwiftGodot\Core\Arguments.swift:110:38: error: value of type 'any Error' has no member 'localizedDescription'
2024-11-06T11:23:04.8174531Z
2024-11-06T11:23:04.8174803Z fatalError(error.localizedDescription)
2024-11-06T11:23:04.8175316Z
2024-11-06T11:23:04.8175514Z ~~~~~ ^~~~~~~~~~~~~~~~~~~~
Oh, that's weird, probably an oversight during a merge-conflict resolution. Should be fixed.
Aha, green now
Something weird happens to CI. @migueldeicaza is there a way to trigger it manually?
This patch is catching a few mistakes in Godot for iPad, so that is very cool!
Some problems that we currently face:
I wonder if we could improve upon some of these.
Many APIs in Godot of the form:
Variant? getSomething()
Are now a bit obnoxious to us, it used to be:
if let text = String(foo.getSomething()) {
Now it needs to be:
if let variant = foo.getSomething(), let text = String(variant) {
I am scared of adding extension methods like "String(Variant?)" or variations because it would affect any place that passes a nil. But we could add it for some of the Godot-based types like "GDictionary", I have a patch here:
I did cheat and on my large code base, I added those extensions, but I am afraid of unleashing this into the unsuspecting public.
My current patch that I think is necessary:
https://gist.github.com/migueldeicaza/afd7c892bd9faa908fe49c159ee29f81
I think something is broken on main branch.
How do you feel about:
extension Optional where Wrapped == Variant {
public func into<T: VariantStorable>(_ type: T.Type = T.self) -> T? {
if let self {
return T.init(self)
} else {
return nil
}
}
public func into<T: VariantStorable>(_ type: T.Type = T.self) -> T? where T: Object {
if let self {
return self.asObject()
} else {
return nil
}
}
}
func foo(_ variant: Variant?) {
if let string = variant.into(String.self) {
}
}
Another observation:
I think that we could annotate some APIs that we know would never pass a nil, like Node.getChildren and a handful of others, for usability purposes.
This PR contains the following changes, all of them are related to
nil
-correctness.Variant
withgtype == .nil
should never surface in the user API. It will be always represented as Swiftnil
ofVariant?
. This allows direct integration of Swift nullability checks into Variant processing. We shouldn't have places where we haveVariant?.some
withGodot
nil
inside. This is accompanied with a lot of small code changes everywhere in the code to support this logic.Variant
will now beVariant?
.ObjectCollection
: TypedArray of objects can now work withnils
(just like it does in GDScript).Nil
builtin class is omitted from translation.Arguments
to streamline gracious failing when Godot calls are done into@Callable
or@Exported
with mismatching arguments. It shouldn't crash the game/editor anymore and print errors instead.MacroCallable
andMacroExported
for newer infrastructure and gracious failing if Godot calls into Swift-exported code with wrong arguments instead of crashing.