From 379bccc4212f5978cb486c45d0b8e43411b7fd6a Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 30 Oct 2024 12:18:03 -0500 Subject: [PATCH 1/2] Support C++ nameless function arguments for C# gen. --- .../Bindings/BindingsGenerator.Parsing.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs index e0fa8572d..fd2fff04a 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs @@ -390,7 +390,22 @@ namespace Flax.Build.Bindings // Read parameter type and name currentParam.Type = ParseType(ref context); - currentParam.Name = context.Tokenizer.ExpectToken(TokenType.Identifier).Value; + token = context.Tokenizer.NextToken(); + if (token.Type == TokenType.Identifier) + { + currentParam.Name = token.Value; + } + // Support nameless arguments. assume optional usage + else + { + context.Tokenizer.PreviousToken(); + if (string.IsNullOrEmpty(currentParam.Attributes)) + currentParam.Attributes = "Optional"; + else + currentParam.Attributes += ", Optional"; + currentParam.Name = $"namelessArg{parameters.Count}"; + } + if (currentParam.IsOut && (currentParam.Type.IsPtr || currentParam.Type.IsRef) && currentParam.Type.Type.EndsWith("*")) { // Pointer to value passed as output pointer From 2f4e673be3e980f91bd5829b5f8b47cd8ee2838f Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 30 Oct 2024 12:20:37 -0500 Subject: [PATCH 2/2] Add test for nameless function arguments --- Source/Engine/Tests/TestScripting.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Engine/Tests/TestScripting.h b/Source/Engine/Tests/TestScripting.h index 476060b0b..cf158fded 100644 --- a/Source/Engine/Tests/TestScripting.h +++ b/Source/Engine/Tests/TestScripting.h @@ -178,6 +178,9 @@ public: return static_cast(number); } + // Test nameless arguments + API_FUNCTION() void TestNamelessArguments(int32, float, bool){} + int32 TestInterfaceMethod(const String& str) override { return str.Length();