Add support for using pointer in MarshalAs in scripting types
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Flax.Build.Bindings
|
||||
public string[] Comment;
|
||||
public bool IsInBuild;
|
||||
public bool IsDeprecated;
|
||||
public string MarshalAs;
|
||||
public TypeInfo MarshalAs;
|
||||
internal bool IsInited;
|
||||
internal TypedefInfo Instigator;
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ namespace Flax.Build.Bindings
|
||||
if (apiType != null)
|
||||
{
|
||||
if (apiType.MarshalAs != null)
|
||||
return UsePassByReference(buildData, new TypeInfo(apiType.MarshalAs), caller);
|
||||
return UsePassByReference(buildData, apiType.MarshalAs, caller);
|
||||
|
||||
// Skip for scripting objects
|
||||
if (apiType.IsScriptingObject)
|
||||
|
||||
@@ -439,7 +439,7 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
|
||||
if (apiType.MarshalAs != null)
|
||||
return GenerateCSharpManagedToNativeType(buildData, new TypeInfo(apiType.MarshalAs), caller);
|
||||
return GenerateCSharpManagedToNativeType(buildData, apiType.MarshalAs, caller);
|
||||
if (apiType.IsScriptingObject || apiType.IsInterface)
|
||||
return "IntPtr";
|
||||
}
|
||||
@@ -531,7 +531,7 @@ namespace Flax.Build.Bindings
|
||||
{
|
||||
var apiType = FindApiTypeInfo(buildData, functionInfo.ReturnType, caller);
|
||||
if (apiType != null && apiType.MarshalAs != null)
|
||||
returnValueType = GenerateCSharpNativeToManaged(buildData, new TypeInfo(apiType.MarshalAs), caller);
|
||||
returnValueType = GenerateCSharpNativeToManaged(buildData, apiType.MarshalAs, caller);
|
||||
else
|
||||
returnValueType = GenerateCSharpNativeToManaged(buildData, functionInfo.ReturnType, caller);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Flax.Build.Bindings
|
||||
partial class BindingsGenerator
|
||||
{
|
||||
private static readonly Dictionary<string, Type> TypeCache = new Dictionary<string, Type>();
|
||||
private const int CacheVersion = 21;
|
||||
private const int CacheVersion = 22;
|
||||
|
||||
internal static void Write(BinaryWriter writer, string e)
|
||||
{
|
||||
|
||||
@@ -597,7 +597,7 @@ namespace Flax.Build.Bindings
|
||||
CppReferencesFiles.Add(apiType.File);
|
||||
|
||||
if (apiType.MarshalAs != null)
|
||||
return GenerateCppWrapperNativeToManaged(buildData, new TypeInfo(apiType.MarshalAs), caller, out type, functionInfo);
|
||||
return GenerateCppWrapperNativeToManaged(buildData, apiType.MarshalAs, caller, out type, functionInfo);
|
||||
|
||||
// Scripting Object
|
||||
if (apiType.IsScriptingObject)
|
||||
@@ -801,7 +801,7 @@ namespace Flax.Build.Bindings
|
||||
if (apiType != null)
|
||||
{
|
||||
if (apiType.MarshalAs != null)
|
||||
return GenerateCppWrapperManagedToNative(buildData, new TypeInfo(apiType.MarshalAs), caller, out type, out apiType, functionInfo, out needLocalVariable);
|
||||
return GenerateCppWrapperManagedToNative(buildData, apiType.MarshalAs, caller, out type, out apiType, functionInfo, out needLocalVariable);
|
||||
|
||||
// Scripting Object (for non-pod types converting only, other API converts managed to unmanaged object in C# wrapper code)
|
||||
if (CppNonPodTypesConvertingGeneration && apiType.IsScriptingObject && typeInfo.IsPtr)
|
||||
|
||||
@@ -185,6 +185,11 @@ namespace Flax.Build.Bindings
|
||||
tag.Value = tag.Value.Substring(1, tag.Value.Length - 2);
|
||||
if (tag.Value.Contains("\\\""))
|
||||
tag.Value = tag.Value.Replace("\\\"", "\"");
|
||||
token = context.Tokenizer.NextToken();
|
||||
if (token.Type == TokenType.Multiply)
|
||||
tag.Value += token.Value;
|
||||
else
|
||||
context.Tokenizer.PreviousToken();
|
||||
parameters.Add(tag);
|
||||
break;
|
||||
case TokenType.Whitespace:
|
||||
@@ -647,7 +652,7 @@ namespace Flax.Build.Bindings
|
||||
desc.Namespace = tag.Value;
|
||||
break;
|
||||
case "marshalas":
|
||||
desc.MarshalAs = tag.Value;
|
||||
desc.MarshalAs = TypeInfo.FromString(tag.Value);
|
||||
break;
|
||||
case "tag":
|
||||
ParseTag(ref desc.Tags, tag);
|
||||
@@ -1236,7 +1241,7 @@ namespace Flax.Build.Bindings
|
||||
desc.Namespace = tag.Value;
|
||||
break;
|
||||
case "marshalas":
|
||||
desc.MarshalAs = tag.Value;
|
||||
desc.MarshalAs = TypeInfo.FromString(tag.Value);
|
||||
break;
|
||||
case "tag":
|
||||
ParseTag(ref desc.Tags, tag);
|
||||
|
||||
@@ -180,6 +180,17 @@ namespace Flax.Build.Bindings
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static TypeInfo FromString(string text)
|
||||
{
|
||||
var result = new TypeInfo(text);
|
||||
if (result.Type.EndsWith('*'))
|
||||
{
|
||||
result.IsPtr = true;
|
||||
result.Type = result.Type.Substring(0, result.Type.Length - 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public string ToString(bool canRef = true)
|
||||
{
|
||||
var sb = new StringBuilder(64);
|
||||
|
||||
Reference in New Issue
Block a user