renamed guid
This commit is contained in:
@@ -44,16 +44,6 @@ namespace Slang
|
|||||||
public const string PluginGuid = "com.biddydev.slang";
|
public const string PluginGuid = "com.biddydev.slang";
|
||||||
public const string PluginName = "Slang";
|
public const string PluginName = "Slang";
|
||||||
|
|
||||||
const string RUST_DLL_NAME = "slang.compiler.dll";
|
|
||||||
|
|
||||||
/// <summary>Takes raw `Slang` source code and compiles it into IC10</summary>
|
|
||||||
[DllImport(RUST_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
private static extern IntPtr compile_from_string(string input);
|
|
||||||
|
|
||||||
/// <summary>Frees memory that was allocated by the FFI call to `compile_from_string`</summary>
|
|
||||||
[DllImport(RUST_DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
private static extern void free_slang_string(IntPtr ptr);
|
|
||||||
|
|
||||||
private static Regex? _slangSourceCheck = null;
|
private static Regex? _slangSourceCheck = null;
|
||||||
|
|
||||||
private static Regex SlangSourceCheck
|
private static Regex SlangSourceCheck
|
||||||
@@ -69,19 +59,28 @@ namespace Slang
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string Compile(string source)
|
public static unsafe string Compile(string source)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(source))
|
if (string.IsNullOrEmpty(source))
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
IntPtr ptr = compile_from_string(source);
|
// Add a null terminator char at the end of the source string (turns into a CStr)
|
||||||
try
|
source += "\0";
|
||||||
|
|
||||||
|
var bytes = System.Text.Encoding.UTF8.GetBytes(source);
|
||||||
|
|
||||||
|
// don't move my memory around, C#!
|
||||||
|
fixed (byte* pBytes = bytes)
|
||||||
{
|
{
|
||||||
return Marshal.PtrToStringAnsi(ptr);
|
var compiled = Ffi.compile_from_string(pBytes);
|
||||||
}
|
try
|
||||||
finally
|
{
|
||||||
{
|
return compiled.AsString();
|
||||||
free_slang_string(ptr);
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Ffi.free_string(compiled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,8 +100,8 @@ namespace Slang
|
|||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
L.SetLogger(Logger);
|
L.SetLogger(Logger);
|
||||||
ExtractNativeDll(RUST_DLL_NAME);
|
ExtractNativeDll("slang.dll");
|
||||||
var harmony = new Harmony("com.dbidwell94.slang");
|
var harmony = new Harmony(PluginGuid);
|
||||||
harmony.PatchAll();
|
harmony.PatchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +116,7 @@ namespace Slang
|
|||||||
if (stream == null)
|
if (stream == null)
|
||||||
{
|
{
|
||||||
L.Error(
|
L.Error(
|
||||||
$"{RUST_DLL_NAME} compiler not found. This means it was not embedded in the mod. Please contact the mod author!"
|
"slang.dll compiler not found. This means it was not embedded in the mod. Please contact the mod author!"
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user