Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
ZyndaDeng committed Nov 10, 2021
1 parent 60d6b13 commit 02036c9
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions sources/engine/Stride.ClearScript/ClearScriptSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,30 @@ public void Initialize()
engine.AddHostType("MSConsole", typeof(Console));
}

public object Execute()
{
return engine.Evaluate(new DocumentInfo { Category = ModuleCategory.Standard }, @"
import * as Arithmetic from 'JavaScript/StandardModule/Arithmetic/Arithmetic.js';
Arithmetic.Add(123, 456);
");
}

public object Evaluate(string code)
{
return engine.Evaluate(code);
return engine.Evaluate(new DocumentInfo { Category = ModuleCategory.Standard }, code);
}

public async Task loadFile(string fileName)
{
using (var stream = VirtualFileSystem.OpenStream(fileName, VirtualFileMode.Open, VirtualFileAccess.Read))
using (var streamReader = new StreamReader(stream))
using var stream = VirtualFileSystem.OpenStream(fileName, VirtualFileMode.Open, VirtualFileAccess.Read);
using var streamReader = new StreamReader(stream);
//read the raw asset content
try
{
string source = await streamReader.ReadToEndAsync();
var path = Path.GetDirectoryName(fileName) + Path.DirectorySeparatorChar;
var doc = new DocumentInfo(new Uri(@"\\js" + path));

doc.Category = ModuleCategory.Standard;
var script = engine.Evaluate(doc, source);
// Console.WriteLine("------javascript c={0}", script.c);
}
catch (Exception e)
{
//read the raw asset content
try
{
string source = await streamReader.ReadToEndAsync();
var path = Path.GetDirectoryName(fileName)+Path.DirectorySeparatorChar;
var doc = new DocumentInfo(new Uri(@"\\js"+path));

doc.Category = ModuleCategory.Standard;
var script = engine.Evaluate(doc, source);
// Console.WriteLine("------javascript c={0}", script.c);
}catch(Exception e)
{
Console.WriteLine(e.Message);
}

Console.WriteLine(e.Message);
}
}

Expand Down

0 comments on commit 02036c9

Please sign in to comment.