diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index d51d7b754..b53c147c2 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -431,6 +431,7 @@ namespace Flax.Build.Bindings private static void GenerateCSharpClass(BuildData buildData, StringBuilder contents, string indent, ClassInfo classInfo) { + var useUnmanaged = classInfo.IsStatic || classInfo.IsScriptingObject; contents.AppendLine(); // Namespace begin @@ -446,7 +447,7 @@ namespace Flax.Build.Bindings GenerateCSharpComment(contents, indent, classInfo.Comment); // Class begin - GenerateCSharpAttributes(buildData, contents, indent, classInfo, true); + GenerateCSharpAttributes(buildData, contents, indent, classInfo, useUnmanaged); contents.Append(indent); if (classInfo.Access == AccessLevel.Public) contents.Append("public "); @@ -482,6 +483,9 @@ namespace Flax.Build.Bindings // Events foreach (var eventInfo in classInfo.Events) { + if (!useUnmanaged) + throw new NotImplementedException("TODO: support events inside non-static and non-scripting API class types."); + contents.AppendLine(); foreach (var comment in eventInfo.Comment) @@ -494,7 +498,7 @@ namespace Flax.Build.Bindings contents.AppendLine(); } - GenerateCSharpAttributes(buildData, contents, indent, eventInfo, true); + GenerateCSharpAttributes(buildData, contents, indent, eventInfo, useUnmanaged); contents.Append(indent); if (eventInfo.Access == AccessLevel.Public) contents.Append("public "); @@ -593,7 +597,7 @@ namespace Flax.Build.Bindings contents.AppendLine(); } - GenerateCSharpAttributes(buildData, contents, indent, fieldInfo, true); + GenerateCSharpAttributes(buildData, contents, indent, fieldInfo, useUnmanaged); contents.Append(indent); if (fieldInfo.Access == AccessLevel.Public) contents.Append("public "); @@ -604,8 +608,13 @@ namespace Flax.Build.Bindings if (fieldInfo.IsStatic) contents.Append("static "); var returnValueType = GenerateCSharpNativeToManaged(buildData, fieldInfo.Type, classInfo); - contents.Append(returnValueType).Append(' ').AppendLine(fieldInfo.Name); - contents.AppendLine(indent + "{"); + contents.Append(returnValueType).Append(' ').Append(fieldInfo.Name); + if (!useUnmanaged) + { + contents.AppendLine(";"); + continue; + } + contents.AppendLine().AppendLine(indent + "{"); indent += " "; contents.Append(indent).Append("get { "); @@ -615,7 +624,7 @@ namespace Flax.Build.Bindings if (!fieldInfo.IsReadOnly) { contents.Append(indent).Append("set { "); - GenerateCSharpWrapperFunctionCall(buildData, contents, classInfo, fieldInfo.Setter, true); + GenerateCSharpWrapperFunctionCall(buildData, contents, classInfo, fieldInfo.Setter, useUnmanaged); contents.Append(" }").AppendLine(); } @@ -630,6 +639,9 @@ namespace Flax.Build.Bindings // Properties foreach (var propertyInfo in classInfo.Properties) { + if (!useUnmanaged) + throw new NotImplementedException("TODO: support properties inside non-static and non-scripting API class types."); + contents.AppendLine(); foreach (var comment in propertyInfo.Comment) @@ -646,7 +658,7 @@ namespace Flax.Build.Bindings contents.AppendLine(); } - GenerateCSharpAttributes(buildData, contents, indent, propertyInfo, true); + GenerateCSharpAttributes(buildData, contents, indent, propertyInfo, useUnmanaged); contents.Append(indent); if (propertyInfo.Access == AccessLevel.Public) contents.Append("public "); @@ -692,6 +704,9 @@ namespace Flax.Build.Bindings // Functions foreach (var functionInfo in classInfo.Functions) { + if (!useUnmanaged) + throw new Exception($"Not supported function {functionInfo.Name} inside non-static and non-scripting class type {classInfo.Name}."); + if (!functionInfo.NoProxy) { contents.AppendLine(); diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs index 393cb9ea5..f9a695b77 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs @@ -1044,6 +1044,7 @@ namespace Flax.Build.Bindings var classTypeNameInternal = classInfo.NativeName; if (classInfo.Parent != null && !(classInfo.Parent is FileInfo)) classTypeNameInternal = classInfo.Parent.FullNameNative + '_' + classTypeNameInternal; + var useUnmanaged = classInfo.IsStatic || classInfo.IsScriptingObject; if (classInfo.IsAutoSerialization) GenerateCppAutoSerialization(buildData, contents, moduleInfo, classInfo, classTypeNameNative); @@ -1056,6 +1057,8 @@ namespace Flax.Build.Bindings // Events foreach (var eventInfo in classInfo.Events) { + if (!useUnmanaged) + continue; CppIncludeFiles.Add("Engine/Scripting/ManagedCLR/MEvent.h"); // C# event invoking wrapper (calls C# event from C++ delegate) @@ -1126,6 +1129,8 @@ namespace Flax.Build.Bindings // Fields foreach (var fieldInfo in classInfo.Fields) { + if (!useUnmanaged) + continue; if (fieldInfo.Getter != null) GenerateCppWrapperFunction(buildData, contents, classInfo, fieldInfo.Getter, "{0}"); if (fieldInfo.Setter != null) @@ -1135,6 +1140,8 @@ namespace Flax.Build.Bindings // Properties foreach (var propertyInfo in classInfo.Properties) { + if (!useUnmanaged) + continue; if (propertyInfo.Getter != null) GenerateCppWrapperFunction(buildData, contents, classInfo, propertyInfo.Getter); if (propertyInfo.Setter != null) @@ -1144,6 +1151,8 @@ namespace Flax.Build.Bindings // Functions foreach (var functionInfo in classInfo.Functions) { + if (!useUnmanaged) + throw new Exception($"Not supported function {functionInfo.Name} inside non-static and non-scripting class type {classInfo.Name}."); GenerateCppWrapperFunction(buildData, contents, classInfo, functionInfo); } @@ -1253,27 +1262,30 @@ namespace Flax.Build.Bindings // Runtime initialization (internal methods binding) contents.AppendLine(" static void InitRuntime()"); contents.AppendLine(" {"); - foreach (var eventInfo in classInfo.Events) + if (useUnmanaged) { - contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{eventInfo.Name}_Bind\", &{eventInfo.Name}_ManagedBind);"); - } - foreach (var fieldInfo in classInfo.Fields) - { - if (fieldInfo.Getter != null) - contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{fieldInfo.Getter.UniqueName}\", &{fieldInfo.Getter.UniqueName});"); - if (fieldInfo.Setter != null) - contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{fieldInfo.Setter.UniqueName}\", &{fieldInfo.Setter.UniqueName});"); - } - foreach (var propertyInfo in classInfo.Properties) - { - if (propertyInfo.Getter != null) - contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{propertyInfo.Getter.UniqueName}\", &{propertyInfo.Getter.UniqueName});"); - if (propertyInfo.Setter != null) - contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{propertyInfo.Setter.UniqueName}\", &{propertyInfo.Setter.UniqueName});"); - } - foreach (var functionInfo in classInfo.Functions) - { - contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{functionInfo.UniqueName}\", &{functionInfo.UniqueName});"); + foreach (var eventInfo in classInfo.Events) + { + contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{eventInfo.Name}_Bind\", &{eventInfo.Name}_ManagedBind);"); + } + foreach (var fieldInfo in classInfo.Fields) + { + if (fieldInfo.Getter != null) + contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{fieldInfo.Getter.UniqueName}\", &{fieldInfo.Getter.UniqueName});"); + if (fieldInfo.Setter != null) + contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{fieldInfo.Setter.UniqueName}\", &{fieldInfo.Setter.UniqueName});"); + } + foreach (var propertyInfo in classInfo.Properties) + { + if (propertyInfo.Getter != null) + contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{propertyInfo.Getter.UniqueName}\", &{propertyInfo.Getter.UniqueName});"); + if (propertyInfo.Setter != null) + contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{propertyInfo.Setter.UniqueName}\", &{propertyInfo.Setter.UniqueName});"); + } + foreach (var functionInfo in classInfo.Functions) + { + contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{functionInfo.UniqueName}\", &{functionInfo.UniqueName});"); + } } GenerateCppClassInitRuntime?.Invoke(buildData, classInfo, contents); @@ -1288,11 +1300,11 @@ namespace Flax.Build.Bindings contents.Append($"StringAnsiView(\"{classTypeNameManaged}\", {classTypeNameManaged.Length}), "); contents.Append($"sizeof({classTypeNameNative}), "); contents.Append($"&{classTypeNameInternal}Internal::InitRuntime, "); - if (!classInfo.IsStatic && !classInfo.NoSpawn) + if (!classInfo.IsStatic && !classInfo.NoSpawn && useUnmanaged) contents.Append($"(ScriptingType::SpawnHandler)&{classTypeNameNative}::Spawn, "); else contents.Append("&ScriptingType::DefaultSpawn, "); - if (classInfo.BaseType != null) + if (classInfo.BaseType != null && useUnmanaged) contents.Append($"&{classInfo.BaseType}::TypeInitializer, "); else contents.Append("nullptr, ");