initial integration with ic10editor mod
This commit is contained in:
@@ -1,29 +1,63 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using StationeersIC10Editor;
|
||||
|
||||
namespace Slang
|
||||
{
|
||||
public static class Marshal
|
||||
{
|
||||
public static unsafe Line TokenizeLine(string input)
|
||||
public static unsafe Line TokenizeLine(string source)
|
||||
{
|
||||
if (String.IsNullOrEmpty(input))
|
||||
if (String.IsNullOrEmpty(source))
|
||||
{
|
||||
return new Line();
|
||||
}
|
||||
|
||||
// Make sure the string is a null terminated string
|
||||
if (input[input.Length - 1] != '\0')
|
||||
L.Info("Input string not empty");
|
||||
|
||||
fixed (char* ptrString = source)
|
||||
{
|
||||
input += '\0';
|
||||
L.Info("In `fixed` block.");
|
||||
var input = new slice_ref_uint16_t
|
||||
{
|
||||
ptr = (ushort*)ptrString,
|
||||
len = (UIntPtr)source.Length,
|
||||
};
|
||||
L.Info("Calling tokenize_line");
|
||||
return Ffi.tokenize_line(input).AsList();
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe bool CompileFromString(string inputString, out string compiledString)
|
||||
{
|
||||
if (String.IsNullOrEmpty(inputString))
|
||||
{
|
||||
compiledString = String.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
var strBytes = Encoding.UTF8.GetBytes(input);
|
||||
|
||||
fixed (byte* ptrString = strBytes)
|
||||
fixed (char* ptrString = inputString)
|
||||
{
|
||||
return Ffi.tokenize_line(ptrString).AsList();
|
||||
var input = new slice_ref_uint16_t
|
||||
{
|
||||
ptr = (ushort*)ptrString,
|
||||
len = (UIntPtr)inputString.Length,
|
||||
};
|
||||
|
||||
var result = Ffi.compile_from_string(input);
|
||||
try
|
||||
{
|
||||
if ((ulong)result.len < 1)
|
||||
{
|
||||
compiledString = String.Empty;
|
||||
return false;
|
||||
}
|
||||
compiledString = result.AsString();
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
result.Drop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user