From 543f634e68ecd2ba805f37f9fa5e4a8e13f8cdb1 Mon Sep 17 00:00:00 2001 From: Marc Hernandez Date: Wed, 28 Sep 2022 22:14:14 -0700 Subject: [PATCH] Fix script proper file handling --- scr/Script.cs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scr/Script.cs b/scr/Script.cs index 4d417ff..1412b03 100644 --- a/scr/Script.cs +++ b/scr/Script.cs @@ -194,19 +194,34 @@ public static class scr public static void CompileFile( string filename, Action onSuccess, Action> onFailure, Platform platform = Platform.X86 ) { - string text = System.IO.File.ReadAllText( filename ); + var fullpath = Path.GetFullPath( filename ); - Compile( text, filename, onSuccess, onFailure ); + //string text = System.IO.File.ReadAllText( fullpath ); + + var stream = File.OpenRead( fullpath ); + + var sourceText = SourceText.From( stream ); + + Compile( sourceText, fullpath, onSuccess, onFailure ); + } + + public static void Compile( string str, string uniquePath, Action onSuccess, Action> onFailure, Platform platform = Platform.X86 ) + { + var sourceText = SourceText.From( str ); + + Compile( sourceText, uniquePath, onSuccess, onFailure ); } - public static void Compile( string script, string uniquePath, Action onSuccess, Action> onFailure, Platform platform = Platform.X86 ) + public static void Compile( SourceText sourceText, string uniquePath, Action onSuccess, Action> onFailure, Platform platform = Platform.X86 ) { string assemblyName = Path.GetRandomFileName(); var options = new CSharpParseOptions(documentationMode: DocumentationMode.Diagnose, kind: SourceCodeKind.Regular); - SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(script, options, uniquePath, encoding: System.Text.Encoding.UTF8); + SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText( sourceText, options, uniquePath ); + + //SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(sourceText, options, uniquePath, encoding: System.Text.Encoding.UTF8); var memRef = new MemoryRefResolver();