public void LoadLibrary() { LibraryBasis.Load(this); LibraryJson.Load(this); LibraryMath.Load(this); LibraryUserdata.Load(this); LibraryIO.Load(this); }
public void LoadLibrary() { LibraryBasis.Load(this); LibraryArray.Load(this); LibraryString.Load(this); LibraryTable.Load(this); LibraryJson.Load(this); LibraryMath.Load(this); LibraryFunc.Load(this); LibraryUserdata.Load(this); LibraryIO.Load(this); }
private static void CheckIO(ILibrary library, LibraryIO io) { using (var memoryStream = new MemoryStream()) { io.Save(library, memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); var loaded = io.Load(memoryStream); Assert.AreEqual(library.Entries.Count, loaded.Entries.Count); for (var i = 0; i != library.Entries.Count; ++i) { var expected = library.Entries[i]; var actual = loaded.Entries[i]; Assert.AreEqual(expected, actual, string.Format("Puzzle #{0} not saved/loaded correctly", i)); } } }
public Script() { Global = new ScriptGlobal(); TypeObject = new ScriptTypeObject("Object"); TypeObjectValue = new ScriptValue(TypeObject); Global.SetValue(TypeObject.TypeName, TypeObjectValue); AddPrimitivePrototype("Bool", ref m_TypeBool, ref m_TypeValueBool); AddPrimitivePrototype("Number", ref m_TypeNumber, ref m_TypeValueNumber); AddPrimitivePrototype("String", ref m_TypeString, ref m_TypeValueString); AddPrimitivePrototype("Function", ref m_TypeFunction, ref m_TypeValueFunction); AddBasicPrototype(m_TypeArray = new ScriptTypeBasicArray(this, "Array", TypeObjectValue), ref m_TypeValueArray); AddBasicPrototype(m_TypeMap = new ScriptTypeBasicMap(this, "Map", TypeObjectValue), ref m_TypeValueMap); AddBasicPrototype(m_TypeStringBuilder = new ScriptTypeBasicStringBuilder(this, "StringBuilder", TypeObjectValue), ref m_TypeValueStringBuilder); Global.SetValue(GLOBAL_NAME, new ScriptValue(Global)); Global.SetValue(GLOBAL_SCRIPT, ScriptValue.CreateValue(this)); Global.SetValue(GLOBAL_VERSION, ScriptValue.CreateValue(typeof(Version))); ProtoObject.Load(this, TypeObject); ProtoBoolean.Load(this, TypeBoolean); ProtoNumber.Load(this, TypeNumber); ProtoString.Load(this, TypeString); ProtoArray.Load(this, TypeArray); ProtoMap.Load(this, TypeMap); ProtoFunction.Load(this, TypeFunction); ProtoStringBuilder.Load(this, TypeStringBuilder); TypeManager.PushAssembly(typeof(object).Assembly); //mscorlib.dll TypeManager.PushAssembly(typeof(System.Net.Sockets.Socket).Assembly); //System.dll TypeManager.PushAssembly(GetType().Assembly); //当前所在的程序集 LibraryBasis.Load(this); LibraryJson.Load(this); LibraryMath.Load(this); LibraryUserdata.Load(this); LibraryIO.Load(this); }
static void Main(string[] args) { script = new Script(); script.LoadLibrary(); script.PushAssembly(typeof(Program).GetTypeInfo().Assembly); #if !SCORPIO_NET_CORE string CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; #else string CurrentDirectory = ""; #endif Console.WriteLine("the current version : " + Script.Version); Console.WriteLine("app path is : " + CurrentDirectory); LoadLibrary(Path.Combine(CurrentDirectory, "dll")); LoadFiles(Path.Combine(CurrentDirectory, "cs")); if (args.Length >= 1) { try { string file = Path.GetFullPath(args[0]); string path = Path.GetDirectoryName(file); LoadLibrary(Path.Combine(path, "dll")); LoadFiles(Path.Combine(path, "cs")); Stopwatch watch = Stopwatch.StartNew(); script.PushSearchPath(CurrentDirectory); script.PushSearchPath(path); script.SetObject("__PATH__", path); LibraryIO.Load(script); Console.WriteLine("============================="); ScriptObject value = script.LoadFile(file); Console.WriteLine("============================="); Console.WriteLine("return value : " + value); Console.WriteLine("the execution time : " + watch.ElapsedMilliseconds + " ms"); } catch (System.Exception ex) { Console.WriteLine(script.GetStackInfo()); Console.WriteLine(ex.ToString()); } } else { while (true) { try { string str = Console.ReadLine(); if (str == "exit") { break; } else if (str == "clear") { Console.Clear(); } else if (str == "version") { Console.WriteLine(Script.Version); } else { script.LoadString(str); } } catch (System.Exception ex) { Console.WriteLine(script.GetStackInfo()); Console.WriteLine(ex.ToString()); } } } }
static void Execute(string[] args) { script = new Script(); script.LoadLibrary(); LibraryIO.Load(script); script.PushAssembly(typeof(Program).Assembly); Console.WriteLine("os version : " + Environment.OSVersion.ToString()); Console.WriteLine("sco version : " + Scorpio.Version.version); Console.WriteLine("build date : " + Scorpio.Version.date); Console.WriteLine("app path is : " + BaseDirectory); Console.WriteLine("environment path is : " + CurrentDirectory); LoadLibrary(Path.Combine(CurrentDirectory, "dll")); if (args.Length >= 1) { try { string file = Path.Combine(CurrentDirectory, args[0]); string path = Path.GetDirectoryName(file); Stopwatch watch = Stopwatch.StartNew(); script.PushSearchPath(path); script.PushSearchPath(CurrentDirectory); script.SetObject("__PATH__", path); Console.WriteLine("============================="); ScriptObject value = script.LoadFile(file); Console.WriteLine("============================="); Console.WriteLine("return value : " + value); Console.WriteLine("the execution time : " + watch.ElapsedMilliseconds + " ms"); } catch (System.Exception ex) { Console.WriteLine(script.GetStackInfo()); Console.WriteLine(ex.ToString()); } } else { while (true) { try { string str = Console.ReadLine(); if (str == "exit") { break; } else if (str == "clear") { Console.Clear(); } else if (str == "version") { Console.WriteLine($@"version : {Scorpio.Version.version} build date : {Scorpio.Version.date}"); } else { script.LoadString(str); } } catch (System.Exception ex) { Console.WriteLine(script.GetStackInfo()); Console.WriteLine(ex.ToString()); } } } }
static void Main(string[] args) { string CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; if ((args.Length == 1 && args[0] == "__RegisterEnvironment")) { var p = new List <string>(Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User).Split(';')); if (!p.Contains(CurrentDirectory)) { p.Add(CurrentDirectory); Environment.SetEnvironmentVariable("Path", string.Join(";", p.ToArray()), EnvironmentVariableTarget.User); } Console.WriteLine("path is already existed"); return; } script = new Script(); script.LoadLibrary(); script.PushAssembly(typeof(Program).GetTypeInfo().Assembly); Console.WriteLine("the current version : " + Script.Version); Console.WriteLine("app path is : " + CurrentDirectory); LoadLibrary(Path.Combine(CurrentDirectory, "dll")); LoadFiles(Path.Combine(CurrentDirectory, "cs")); if (args.Length >= 1) { try { string file = Path.GetFullPath(args[0]); string path = Path.GetDirectoryName(file); LoadLibrary(Path.Combine(path, "dll")); LoadFiles(Path.Combine(path, "cs")); Stopwatch watch = Stopwatch.StartNew(); script.PushSearchPath(CurrentDirectory); script.PushSearchPath(path); script.SetObject("__PATH__", path); script.SetObject("print", script.CreateFunction(new print())); LibraryIO.Load(script); Console.WriteLine("============================="); ScriptObject value = script.LoadFile(file); Console.WriteLine("============================="); Console.WriteLine("return value : " + value); Console.WriteLine("the execution time : " + watch.ElapsedMilliseconds + " ms"); } catch (System.Exception ex) { Console.WriteLine(script.GetStackInfo()); Console.WriteLine(ex.ToString()); } } else { while (true) { try { string str = Console.ReadLine(); if (str == "exit") { break; } else if (str == "clear") { Console.Clear(); } else if (str == "version") { Console.WriteLine(Script.Version); } else { script.LoadString(str); } } catch (System.Exception ex) { Console.WriteLine(script.GetStackInfo()); Console.WriteLine(ex.ToString()); } } } }
static void Main(string[] args) { Script script = new Script(); Console.WriteLine("开始执行,当前版本:" + Script.Version); script.LoadLibrary(); script.PushAssembly(typeof(Program).Assembly); if (Directory.Exists(CurrentDirectory + "/Library")) { string[] files = Directory.GetFiles(CurrentDirectory + "/Library", "*.dll", SearchOption.AllDirectories); foreach (var file in files) { try { script.PushAssembly(Assembly.LoadFile(file)); Console.WriteLine("导入文件[" + file + "]成功"); } catch (System.Exception ex) { Console.WriteLine("导入文件[" + file + "]失败 " + ex.ToString()); } } } if (Directory.Exists(CurrentDirectory + "/Program")) { try { script.PushAssembly(CompilerFile(CurrentDirectory + "/Program")); } catch (System.Exception ex) { Console.WriteLine("编译文件失败 " + ex.ToString()); } } if (args.Length >= 1) { try { Stopwatch watch = Stopwatch.StartNew(); script.PushSearchPath(CurrentDirectory); script.PushSearchPath(Path.GetDirectoryName(args[0])); LibraryIO.Load(script); Console.WriteLine("返回值为:" + script.LoadFile(args[0])); Console.WriteLine("运行时间:" + watch.ElapsedMilliseconds + " ms"); } catch (System.Exception ex) { Console.WriteLine(script.GetStackInfo()); Console.WriteLine(ex.ToString()); } Console.ReadKey(); } else { while (true) { try { string str = Console.ReadLine(); if (str == "exit") { break; } else if (str == "clear") { Console.Clear(); } else if (str == "version") { Console.WriteLine(Script.Version); } else { script.LoadString(str); } } catch (System.Exception ex) { Console.WriteLine(script.GetStackInfo()); Console.WriteLine(ex.ToString()); } } } }