diff --git a/Source/Engine/Core/Types/Span.h b/Source/Engine/Core/Types/Span.h index d0cbd7993..678550e85 100644 --- a/Source/Engine/Core/Types/Span.h +++ b/Source/Engine/Core/Types/Span.h @@ -8,7 +8,7 @@ /// Universal representation of a contiguous region of arbitrary memory. /// template -class Span +API_CLASS(InBuild) class Span { protected: T* _data; diff --git a/Source/Engine/Scripting/ManagedCLR/MUtils.h b/Source/Engine/Scripting/ManagedCLR/MUtils.h index e33e22719..7f7480b0a 100644 --- a/Source/Engine/Scripting/ManagedCLR/MUtils.h +++ b/Source/Engine/Scripting/ManagedCLR/MUtils.h @@ -499,8 +499,8 @@ namespace MUtils /// /// The native array object. /// The output array pointer and size. - template - FORCE_INLINE Span ToSpan(const Array& data) + template + FORCE_INLINE Span ToSpan(const Array& data) { return Span(data.Get(), data.Count()); } diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs index 56419d87c..9acaf1f9c 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs @@ -172,6 +172,10 @@ namespace Flax.Build.Bindings CppVariantFromTypes[wrapperName] = typeInfo; return $"VariantFrom{wrapperName}Dictionary({value})"; } + if (typeInfo.Type == "Span" && typeInfo.GenericArgs != null) + { + return "Variant()"; // TODO: Span to Variant converting (use utility method the same way as for arrays) + } var apiType = FindApiTypeInfo(buildData, typeInfo, caller); if (apiType != null) @@ -218,6 +222,10 @@ namespace Flax.Build.Bindings CppVariantToTypes.Add(typeInfo); return $"MoveTemp(VariantTo{GenerateCppWrapperNativeToVariantMethodName(typeInfo)}({value}))"; } + if (typeInfo.Type == "Span" && typeInfo.GenericArgs != null) + { + return $"{typeInfo}()"; // Cannot be implemented since Variant stores array of Variants thus cannot get linear span of data + } var apiType = FindApiTypeInfo(buildData, typeInfo, caller); if (apiType != null) @@ -482,13 +490,20 @@ namespace Flax.Build.Bindings return "{0}.GetManagedInstance()"; } - // Array or Span or DataContainer + // Array or DataContainer if ((typeInfo.Type == "Array" || typeInfo.Type == "Span" || typeInfo.Type == "DataContainer") && typeInfo.GenericArgs != null) { type = "MonoArray*"; return "MUtils::ToArray({0}, " + GenerateCppGetNativeClass(buildData, typeInfo.GenericArgs[0], caller, functionInfo) + ")"; } + // Span + if (typeInfo.Type == "Span" && typeInfo.GenericArgs != null) + { + type = "MonoArray*"; + return "MUtils::Span({0}, " + GenerateCppGetNativeClass(buildData, typeInfo.GenericArgs[0], caller, functionInfo) + ")"; + } + // BytesContainer if (typeInfo.Type == "BytesContainer" && typeInfo.GenericArgs == null) {