Skip to content

Commit

Permalink
fix: Future<void> should return null if asked to be put in a variant.
Browse files Browse the repository at this point in the history
Also minor fix for Dart templates to use super parameters.

refs: #20
  • Loading branch information
fuzzybinary committed Oct 26, 2024
1 parent 5fe1ea7 commit 836121c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/cpp/editor/dart_templates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -53,8 +51,8 @@ const char *dart_script = "import 'dart:ffi';\n"
"\n"
" __CLASS_NAME__() : super();\n"
"\n"
" __CLASS_NAME__.withNonNullOwner(Pointer<Void> owner)\n"
" :super.withNonNullOwner(owner);\n"
" __CLASS_NAME__.withNonNullOwner(super.owner)\n"
" :super.withNonNullOwner();\n"
"\n"
" @override\n"
" void vReady() {\n"
Expand Down
8 changes: 8 additions & 0 deletions src/dart/godot_dart/lib/src/variant/variant.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:ffi';

import 'package:ffi/ffi.dart';
Expand Down Expand Up @@ -259,6 +260,13 @@ class Variant implements Finalizable {
GDExtensionVariantType.GDEXTENSION_VARIANT_TYPE_STRING];
c!(nativePtr.cast(), gdString.nativePtr.cast());
break;
case final Future<void> _:
// 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<void>
gde.ffiBindings.gde_variant_new_nil(nativePtr.cast());
break;
// TODO: All the other variant types (dictionary? List?)
default:
throw ArgumentError(
Expand Down

0 comments on commit 836121c

Please sign in to comment.