From 836121ccbc0608224f518cb8b2cd6e29bae7eee7 Mon Sep 17 00:00:00 2001 From: Jeff Ward Date: Sat, 26 Oct 2024 17:19:26 -0400 Subject: [PATCH] fix: Future should return null if asked to be put in a variant. Also minor fix for Dart templates to use super parameters. refs: #20 --- src/cpp/editor/dart_templates.cpp | 8 +++----- src/dart/godot_dart/lib/src/variant/variant.dart | 8 ++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/cpp/editor/dart_templates.cpp b/src/cpp/editor/dart_templates.cpp index 8b82486..a525026 100644 --- a/src/cpp/editor/dart_templates.cpp +++ b/src/cpp/editor/dart_templates.cpp @@ -39,9 +39,7 @@ const char *git_ignore_template = "# Files and directories created by pub\n" "\n"; -const char *dart_script = "import 'dart:ffi';\n" - "\n" - "import 'package:godot_dart/godot_dart.dart';\n" +const char *dart_script = "import 'package:godot_dart/godot_dart.dart';\n" "\n" "part '__FILE_NAME__.g.dart';\n" "\n" @@ -53,8 +51,8 @@ const char *dart_script = "import 'dart:ffi';\n" "\n" " __CLASS_NAME__() : super();\n" "\n" - " __CLASS_NAME__.withNonNullOwner(Pointer owner)\n" - " :super.withNonNullOwner(owner);\n" + " __CLASS_NAME__.withNonNullOwner(super.owner)\n" + " :super.withNonNullOwner();\n" "\n" " @override\n" " void vReady() {\n" diff --git a/src/dart/godot_dart/lib/src/variant/variant.dart b/src/dart/godot_dart/lib/src/variant/variant.dart index 0da589c..edbb04f 100644 --- a/src/dart/godot_dart/lib/src/variant/variant.dart +++ b/src/dart/godot_dart/lib/src/variant/variant.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:ffi'; import 'package:ffi/ffi.dart'; @@ -259,6 +260,13 @@ class Variant implements Finalizable { GDExtensionVariantType.GDEXTENSION_VARIANT_TYPE_STRING]; c!(nativePtr.cast(), gdString.nativePtr.cast()); break; + case final Future _: + // Allow FutureOr and Future void to be return types, but not + // others. This simply returns the variant 'nil'. This is + // specifically for async signal recievers, which return + // FutureOr + gde.ffiBindings.gde_variant_new_nil(nativePtr.cast()); + break; // TODO: All the other variant types (dictionary? List?) default: throw ArgumentError(