wip -- marshal UTF16 string from C# to Rust to avoid GC in C#

This commit is contained in:
2025-11-28 14:44:26 -07:00
parent 036be297ea
commit e274b33553
7 changed files with 52 additions and 14 deletions

30
csharp_mod/Marshal.cs Normal file
View File

@@ -0,0 +1,30 @@
using System;
using System.Text;
using StationeersIC10Editor;
namespace Slang
{
public static class Marshal
{
public static unsafe Line TokenizeLine(string input)
{
if (String.IsNullOrEmpty(input))
{
return new Line();
}
// Make sure the string is a null terminated string
if (input[input.Length - 1] != '\0')
{
input += '\0';
}
var strBytes = Encoding.UTF8.GetBytes(input);
fixed (byte* ptrString = strBytes)
{
return Ffi.tokenize_line(ptrString).AsList();
}
}
}
}