wip -- marshal UTF16 string from C# to Rust to avoid GC in C#
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using StationeersIC10Editor;
|
||||
|
||||
@@ -27,9 +26,11 @@ namespace Slang
|
||||
}
|
||||
|
||||
// 2. Convert Rust Token Vector to C# List
|
||||
public static List<Token> AsList(this Vec_FfiToken_t vec)
|
||||
public static Line AsList(this Vec_FfiToken_t vec)
|
||||
{
|
||||
var list = new List<Token>((int)vec.len);
|
||||
var list = new Line();
|
||||
list.Capacity = (int)vec.len;
|
||||
|
||||
var currentPtr = vec.ptr;
|
||||
|
||||
// Iterate through the raw memory array
|
||||
@@ -6,7 +6,7 @@ namespace Slang
|
||||
{
|
||||
public override Line ParseLine(string line)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
return Marshal.TokenizeLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
30
csharp_mod/Marshal.cs
Normal file
30
csharp_mod/Marshal.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using BepInEx;
|
||||
using HarmonyLib;
|
||||
using StationeersIC10Editor;
|
||||
|
||||
namespace Slang
|
||||
{
|
||||
@@ -103,6 +102,7 @@ namespace Slang
|
||||
ExtractNativeDll("slang.dll");
|
||||
var harmony = new Harmony(PluginGuid);
|
||||
harmony.PatchAll();
|
||||
CodeFormatters.RegisterFormatter("slang", () => new SlangFormatter(), true);
|
||||
}
|
||||
|
||||
private void ExtractNativeDll(string fileName)
|
||||
Reference in New Issue
Block a user