Add support for API class not using ScriptingObject as a base
This commit is contained in:
@@ -431,6 +431,7 @@ namespace Flax.Build.Bindings
|
|||||||
|
|
||||||
private static void GenerateCSharpClass(BuildData buildData, StringBuilder contents, string indent, ClassInfo classInfo)
|
private static void GenerateCSharpClass(BuildData buildData, StringBuilder contents, string indent, ClassInfo classInfo)
|
||||||
{
|
{
|
||||||
|
var useUnmanaged = classInfo.IsStatic || classInfo.IsScriptingObject;
|
||||||
contents.AppendLine();
|
contents.AppendLine();
|
||||||
|
|
||||||
// Namespace begin
|
// Namespace begin
|
||||||
@@ -446,7 +447,7 @@ namespace Flax.Build.Bindings
|
|||||||
GenerateCSharpComment(contents, indent, classInfo.Comment);
|
GenerateCSharpComment(contents, indent, classInfo.Comment);
|
||||||
|
|
||||||
// Class begin
|
// Class begin
|
||||||
GenerateCSharpAttributes(buildData, contents, indent, classInfo, true);
|
GenerateCSharpAttributes(buildData, contents, indent, classInfo, useUnmanaged);
|
||||||
contents.Append(indent);
|
contents.Append(indent);
|
||||||
if (classInfo.Access == AccessLevel.Public)
|
if (classInfo.Access == AccessLevel.Public)
|
||||||
contents.Append("public ");
|
contents.Append("public ");
|
||||||
@@ -482,6 +483,9 @@ namespace Flax.Build.Bindings
|
|||||||
// Events
|
// Events
|
||||||
foreach (var eventInfo in classInfo.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();
|
contents.AppendLine();
|
||||||
|
|
||||||
foreach (var comment in eventInfo.Comment)
|
foreach (var comment in eventInfo.Comment)
|
||||||
@@ -494,7 +498,7 @@ namespace Flax.Build.Bindings
|
|||||||
contents.AppendLine();
|
contents.AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
GenerateCSharpAttributes(buildData, contents, indent, eventInfo, true);
|
GenerateCSharpAttributes(buildData, contents, indent, eventInfo, useUnmanaged);
|
||||||
contents.Append(indent);
|
contents.Append(indent);
|
||||||
if (eventInfo.Access == AccessLevel.Public)
|
if (eventInfo.Access == AccessLevel.Public)
|
||||||
contents.Append("public ");
|
contents.Append("public ");
|
||||||
@@ -593,7 +597,7 @@ namespace Flax.Build.Bindings
|
|||||||
contents.AppendLine();
|
contents.AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
GenerateCSharpAttributes(buildData, contents, indent, fieldInfo, true);
|
GenerateCSharpAttributes(buildData, contents, indent, fieldInfo, useUnmanaged);
|
||||||
contents.Append(indent);
|
contents.Append(indent);
|
||||||
if (fieldInfo.Access == AccessLevel.Public)
|
if (fieldInfo.Access == AccessLevel.Public)
|
||||||
contents.Append("public ");
|
contents.Append("public ");
|
||||||
@@ -604,8 +608,13 @@ namespace Flax.Build.Bindings
|
|||||||
if (fieldInfo.IsStatic)
|
if (fieldInfo.IsStatic)
|
||||||
contents.Append("static ");
|
contents.Append("static ");
|
||||||
var returnValueType = GenerateCSharpNativeToManaged(buildData, fieldInfo.Type, classInfo);
|
var returnValueType = GenerateCSharpNativeToManaged(buildData, fieldInfo.Type, classInfo);
|
||||||
contents.Append(returnValueType).Append(' ').AppendLine(fieldInfo.Name);
|
contents.Append(returnValueType).Append(' ').Append(fieldInfo.Name);
|
||||||
contents.AppendLine(indent + "{");
|
if (!useUnmanaged)
|
||||||
|
{
|
||||||
|
contents.AppendLine(";");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
contents.AppendLine().AppendLine(indent + "{");
|
||||||
indent += " ";
|
indent += " ";
|
||||||
|
|
||||||
contents.Append(indent).Append("get { ");
|
contents.Append(indent).Append("get { ");
|
||||||
@@ -615,7 +624,7 @@ namespace Flax.Build.Bindings
|
|||||||
if (!fieldInfo.IsReadOnly)
|
if (!fieldInfo.IsReadOnly)
|
||||||
{
|
{
|
||||||
contents.Append(indent).Append("set { ");
|
contents.Append(indent).Append("set { ");
|
||||||
GenerateCSharpWrapperFunctionCall(buildData, contents, classInfo, fieldInfo.Setter, true);
|
GenerateCSharpWrapperFunctionCall(buildData, contents, classInfo, fieldInfo.Setter, useUnmanaged);
|
||||||
contents.Append(" }").AppendLine();
|
contents.Append(" }").AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -630,6 +639,9 @@ namespace Flax.Build.Bindings
|
|||||||
// Properties
|
// Properties
|
||||||
foreach (var propertyInfo in classInfo.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();
|
contents.AppendLine();
|
||||||
|
|
||||||
foreach (var comment in propertyInfo.Comment)
|
foreach (var comment in propertyInfo.Comment)
|
||||||
@@ -646,7 +658,7 @@ namespace Flax.Build.Bindings
|
|||||||
contents.AppendLine();
|
contents.AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
GenerateCSharpAttributes(buildData, contents, indent, propertyInfo, true);
|
GenerateCSharpAttributes(buildData, contents, indent, propertyInfo, useUnmanaged);
|
||||||
contents.Append(indent);
|
contents.Append(indent);
|
||||||
if (propertyInfo.Access == AccessLevel.Public)
|
if (propertyInfo.Access == AccessLevel.Public)
|
||||||
contents.Append("public ");
|
contents.Append("public ");
|
||||||
@@ -692,6 +704,9 @@ namespace Flax.Build.Bindings
|
|||||||
// Functions
|
// Functions
|
||||||
foreach (var functionInfo in classInfo.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)
|
if (!functionInfo.NoProxy)
|
||||||
{
|
{
|
||||||
contents.AppendLine();
|
contents.AppendLine();
|
||||||
|
|||||||
@@ -1044,6 +1044,7 @@ namespace Flax.Build.Bindings
|
|||||||
var classTypeNameInternal = classInfo.NativeName;
|
var classTypeNameInternal = classInfo.NativeName;
|
||||||
if (classInfo.Parent != null && !(classInfo.Parent is FileInfo))
|
if (classInfo.Parent != null && !(classInfo.Parent is FileInfo))
|
||||||
classTypeNameInternal = classInfo.Parent.FullNameNative + '_' + classTypeNameInternal;
|
classTypeNameInternal = classInfo.Parent.FullNameNative + '_' + classTypeNameInternal;
|
||||||
|
var useUnmanaged = classInfo.IsStatic || classInfo.IsScriptingObject;
|
||||||
|
|
||||||
if (classInfo.IsAutoSerialization)
|
if (classInfo.IsAutoSerialization)
|
||||||
GenerateCppAutoSerialization(buildData, contents, moduleInfo, classInfo, classTypeNameNative);
|
GenerateCppAutoSerialization(buildData, contents, moduleInfo, classInfo, classTypeNameNative);
|
||||||
@@ -1056,6 +1057,8 @@ namespace Flax.Build.Bindings
|
|||||||
// Events
|
// Events
|
||||||
foreach (var eventInfo in classInfo.Events)
|
foreach (var eventInfo in classInfo.Events)
|
||||||
{
|
{
|
||||||
|
if (!useUnmanaged)
|
||||||
|
continue;
|
||||||
CppIncludeFiles.Add("Engine/Scripting/ManagedCLR/MEvent.h");
|
CppIncludeFiles.Add("Engine/Scripting/ManagedCLR/MEvent.h");
|
||||||
|
|
||||||
// C# event invoking wrapper (calls C# event from C++ delegate)
|
// C# event invoking wrapper (calls C# event from C++ delegate)
|
||||||
@@ -1126,6 +1129,8 @@ namespace Flax.Build.Bindings
|
|||||||
// Fields
|
// Fields
|
||||||
foreach (var fieldInfo in classInfo.Fields)
|
foreach (var fieldInfo in classInfo.Fields)
|
||||||
{
|
{
|
||||||
|
if (!useUnmanaged)
|
||||||
|
continue;
|
||||||
if (fieldInfo.Getter != null)
|
if (fieldInfo.Getter != null)
|
||||||
GenerateCppWrapperFunction(buildData, contents, classInfo, fieldInfo.Getter, "{0}");
|
GenerateCppWrapperFunction(buildData, contents, classInfo, fieldInfo.Getter, "{0}");
|
||||||
if (fieldInfo.Setter != null)
|
if (fieldInfo.Setter != null)
|
||||||
@@ -1135,6 +1140,8 @@ namespace Flax.Build.Bindings
|
|||||||
// Properties
|
// Properties
|
||||||
foreach (var propertyInfo in classInfo.Properties)
|
foreach (var propertyInfo in classInfo.Properties)
|
||||||
{
|
{
|
||||||
|
if (!useUnmanaged)
|
||||||
|
continue;
|
||||||
if (propertyInfo.Getter != null)
|
if (propertyInfo.Getter != null)
|
||||||
GenerateCppWrapperFunction(buildData, contents, classInfo, propertyInfo.Getter);
|
GenerateCppWrapperFunction(buildData, contents, classInfo, propertyInfo.Getter);
|
||||||
if (propertyInfo.Setter != null)
|
if (propertyInfo.Setter != null)
|
||||||
@@ -1144,6 +1151,8 @@ namespace Flax.Build.Bindings
|
|||||||
// Functions
|
// Functions
|
||||||
foreach (var functionInfo in classInfo.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);
|
GenerateCppWrapperFunction(buildData, contents, classInfo, functionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1253,27 +1262,30 @@ namespace Flax.Build.Bindings
|
|||||||
// Runtime initialization (internal methods binding)
|
// Runtime initialization (internal methods binding)
|
||||||
contents.AppendLine(" static void InitRuntime()");
|
contents.AppendLine(" static void InitRuntime()");
|
||||||
contents.AppendLine(" {");
|
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 eventInfo in classInfo.Events)
|
||||||
}
|
{
|
||||||
foreach (var fieldInfo in classInfo.Fields)
|
contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{eventInfo.Name}_Bind\", &{eventInfo.Name}_ManagedBind);");
|
||||||
{
|
}
|
||||||
if (fieldInfo.Getter != null)
|
foreach (var fieldInfo in classInfo.Fields)
|
||||||
contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{fieldInfo.Getter.UniqueName}\", &{fieldInfo.Getter.UniqueName});");
|
{
|
||||||
if (fieldInfo.Setter != null)
|
if (fieldInfo.Getter != null)
|
||||||
contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{fieldInfo.Setter.UniqueName}\", &{fieldInfo.Setter.UniqueName});");
|
contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{fieldInfo.Getter.UniqueName}\", &{fieldInfo.Getter.UniqueName});");
|
||||||
}
|
if (fieldInfo.Setter != null)
|
||||||
foreach (var propertyInfo in classInfo.Properties)
|
contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{fieldInfo.Setter.UniqueName}\", &{fieldInfo.Setter.UniqueName});");
|
||||||
{
|
}
|
||||||
if (propertyInfo.Getter != null)
|
foreach (var propertyInfo in classInfo.Properties)
|
||||||
contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{propertyInfo.Getter.UniqueName}\", &{propertyInfo.Getter.UniqueName});");
|
{
|
||||||
if (propertyInfo.Setter != null)
|
if (propertyInfo.Getter != null)
|
||||||
contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{propertyInfo.Setter.UniqueName}\", &{propertyInfo.Setter.UniqueName});");
|
contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{propertyInfo.Getter.UniqueName}\", &{propertyInfo.Getter.UniqueName});");
|
||||||
}
|
if (propertyInfo.Setter != null)
|
||||||
foreach (var functionInfo in classInfo.Functions)
|
contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{propertyInfo.Setter.UniqueName}\", &{propertyInfo.Setter.UniqueName});");
|
||||||
{
|
}
|
||||||
contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{functionInfo.UniqueName}\", &{functionInfo.UniqueName});");
|
foreach (var functionInfo in classInfo.Functions)
|
||||||
|
{
|
||||||
|
contents.AppendLine($" ADD_INTERNAL_CALL(\"{classTypeNameManagedInternalCall}::Internal_{functionInfo.UniqueName}\", &{functionInfo.UniqueName});");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
GenerateCppClassInitRuntime?.Invoke(buildData, classInfo, contents);
|
GenerateCppClassInitRuntime?.Invoke(buildData, classInfo, contents);
|
||||||
|
|
||||||
@@ -1288,11 +1300,11 @@ namespace Flax.Build.Bindings
|
|||||||
contents.Append($"StringAnsiView(\"{classTypeNameManaged}\", {classTypeNameManaged.Length}), ");
|
contents.Append($"StringAnsiView(\"{classTypeNameManaged}\", {classTypeNameManaged.Length}), ");
|
||||||
contents.Append($"sizeof({classTypeNameNative}), ");
|
contents.Append($"sizeof({classTypeNameNative}), ");
|
||||||
contents.Append($"&{classTypeNameInternal}Internal::InitRuntime, ");
|
contents.Append($"&{classTypeNameInternal}Internal::InitRuntime, ");
|
||||||
if (!classInfo.IsStatic && !classInfo.NoSpawn)
|
if (!classInfo.IsStatic && !classInfo.NoSpawn && useUnmanaged)
|
||||||
contents.Append($"(ScriptingType::SpawnHandler)&{classTypeNameNative}::Spawn, ");
|
contents.Append($"(ScriptingType::SpawnHandler)&{classTypeNameNative}::Spawn, ");
|
||||||
else
|
else
|
||||||
contents.Append("&ScriptingType::DefaultSpawn, ");
|
contents.Append("&ScriptingType::DefaultSpawn, ");
|
||||||
if (classInfo.BaseType != null)
|
if (classInfo.BaseType != null && useUnmanaged)
|
||||||
contents.Append($"&{classInfo.BaseType}::TypeInitializer, ");
|
contents.Append($"&{classInfo.BaseType}::TypeInitializer, ");
|
||||||
else
|
else
|
||||||
contents.Append("nullptr, ");
|
contents.Append("nullptr, ");
|
||||||
|
|||||||
Reference in New Issue
Block a user