Fixed calling engine functions from scripts

- Removed mono references in generator
- Implemented StringView type in C#
This commit is contained in:
Simon Lübeß
2025-08-08 19:03:09 +02:00
parent 042ae83a0f
commit d156618453
10 changed files with 330 additions and 277 deletions
+11 -30
View File
@@ -194,36 +194,6 @@ public class ScriptGlueGenerator : IIncrementalGenerator
ReturnValueConversion = null
});
beefTypeToMappedType.Add("Mono.MonoString*", new MappedType
{
BeefTypeName = "object /*TODO: Mono.MonoString**/",
ReturnValueConversion = null
});
beefTypeToMappedType.Add("Mono.MonoException*", new MappedType
{
BeefTypeName = "object /*TODO: Mono.MonoException**/",
ReturnValueConversion = null
});
beefTypeToMappedType.Add("Mono.MonoArray*", new MappedType
{
BeefTypeName = "object /*TODO: Mono.MonoArray**/",
ReturnValueConversion = null
});
beefTypeToMappedType.Add("Mono.MonoObject*", new MappedType
{
BeefTypeName = "object /*TODO: Mono.MonoObject**/",
ReturnValueConversion = null
});
beefTypeToMappedType.Add("Mono.MonoReflectionType*", new MappedType
{
BeefTypeName = "object /*TODO: Mono.MonoReflectionType**/",
ReturnValueConversion = null
});
beefTypeToMappedType.Add("uint8*", new MappedType
{
BeefTypeName = "uint8*",
@@ -287,6 +257,17 @@ public class ScriptGlueGenerator : IIncrementalGenerator
CSharpWrapperType = "bool",
ReturnValueConversion = "EngineErrors.ThrowIfError(returnValue);\nreturn (returnValue == EngineResult.Ok);"
});
beefTypeToMappedType.Add("System.StringView", new MappedType()
{
BeefTypeName = "System.StringView",
CSharpTypeName = "GlitchyEngine.Native.StringView",
CSharpWrapperType = "string",
ReturnValueConversion = "return returnValue.ToString();",
WrapperConvertInput = "var {0} = GlitchyEngine.Native.StringView.FromManagedString({1});",
WrapperCleanupInput = "GlitchyEngine.Native.StringView.FreeNativeMemory({0});",
WrapperOutConversion = "{1} = {0}.ToString();"
});
}
private static void GenerateFunctionPointer(GlueMethod method, Dictionary<string, MappedType> beefTypeToMappedType, StringBuilder output)