mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Remove mono from Glue functions
This commit is contained in:
@@ -100,6 +100,8 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
||||
public string? WrapperConvertInput;
|
||||
public string? WrapperCleanupInput;
|
||||
|
||||
public string? WrapperOutConversion;
|
||||
|
||||
public string? ReturnValueConversion = "return returnValue;";
|
||||
|
||||
public string CSharpWrapperType
|
||||
@@ -237,6 +239,17 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
||||
WrapperConvertInput = "fixed (char* {0} = {1}) {{",
|
||||
WrapperCleanupInput = "}}"
|
||||
});
|
||||
|
||||
beefTypeToMappedType.Add("char8*", new MappedType
|
||||
{
|
||||
BeefTypeName = "char8*",
|
||||
CSharpTypeName = "byte*",
|
||||
CSharpWrapperType = "string",
|
||||
ReturnValueConversion = "return Marshal.PtrToStringUTF8((IntPtr)returnValue);",
|
||||
WrapperConvertInput = "byte* {0} = (byte*)Marshal.StringToCoTaskMemUTF8({1});",
|
||||
WrapperCleanupInput = "Marshal.FreeCoTaskMem((IntPtr){0});",
|
||||
WrapperOutConversion = "{1} = Marshal.PtrToStringUTF8((IntPtr){0}) ?? \"\";"
|
||||
});
|
||||
|
||||
beefTypeToMappedType.Add("int32", new MappedType
|
||||
{
|
||||
@@ -249,6 +262,16 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
||||
BeefTypeName = "System.Numerics.Quaternion",
|
||||
ReturnValueConversion = null
|
||||
});
|
||||
|
||||
beefTypeToMappedType.Add("void*", new MappedType
|
||||
{
|
||||
BeefTypeName = "void*",
|
||||
CSharpTypeName = "void*",
|
||||
CSharpWrapperType = "IntPtr",
|
||||
ReturnValueConversion = "return (IntPtr)returnValue;",
|
||||
WrapperConvertInput = "void* {0} = (void*){1};",
|
||||
WrapperOutConversion = "{1} = (IntPtr){0};"
|
||||
});
|
||||
}
|
||||
|
||||
private static void GenerateFunctionPointer(GlueMethod method, Dictionary<string, MappedType> beefTypeToMappedType, StringBuilder output)
|
||||
@@ -341,7 +364,17 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
||||
break;
|
||||
}
|
||||
|
||||
if (parameterType.WrapperConvertInput is not null)
|
||||
if (parameterModifier == TypeModifier.Out && parameterType.WrapperOutConversion is not null)
|
||||
{
|
||||
string tmpArgName = $"{param.Name}Tmp";
|
||||
|
||||
call.Append($"var {tmpArgName}");
|
||||
|
||||
cleanup.Append("\t\t");
|
||||
cleanup.AppendFormat(parameterType.WrapperOutConversion, tmpArgName, param.Name);
|
||||
cleanup.AppendLine();
|
||||
}
|
||||
else if (parameterType.WrapperConvertInput is not null)
|
||||
{
|
||||
string convertedParamName = $"{param.Name}Converted";
|
||||
|
||||
@@ -422,7 +455,9 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
||||
|
||||
wrappers.Append("""
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace GlitchyEngine;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user