void Start() { try { DefaultScriptUserdataDelegateType.SetFactory(new DelegateFactory()); List<string> scripts = new List<string>(); scripts.Add("window"); Script script = new Script(); Launch.Script = script; script.LoadLibrary(); script.PushAssembly(typeof(int).Assembly); script.PushAssembly(typeof(GameObject).Assembly); script.PushAssembly(GetType().Assembly); script.SetObject("print", new ScorpioFunction(Print)); for (int i = 0; i < scripts.Count; ++i) { script.LoadString(scripts[i], (Resources.Load(scripts[i]) as TextAsset).text); } Util.AddComponent(obj, (ScriptTable)script.GetValue("window")); } catch (System.Exception ex) { Debug.LogError("Stack : " + Script.GetStackInfo()); Debug.LogError("Start is error " + ex.ToString()); } }
void OnGUI() { text = GUI.TextArea(new Rect(0, 0, width, windowHeight), text); url = GUI.TextField(new Rect(0, windowHeight, width, 30), url); PlayerPrefs.SetString("__Text", text); PlayerPrefs.SetString("__Url", url); if (GUI.Button(new Rect(0, windowHeight + 30, width / 2, 60), "RunScript (" + Script.Version + ")")) { output = ""; Script script = new Script(); try { script.LoadLibrary(); script.PushAssembly(GetType().Assembly); script.PushAssembly(typeof(GameObject).Assembly); script.SetObject("print", script.CreateFunction(print)); ScriptObject ret = script.LoadString(text); OutPut("ReturnValue : " + ret); } catch (System.Exception e) { OutPut("StackInfo : " + script.GetStackInfo()); OutPut(e.ToString()); } } if (GUI.Button(new Rect(width / 2, windowHeight + 30, width / 2, 60), "GetScript")) { SendMessage("GetScript"); } GUI.TextArea(new Rect(0, windowHeight + 90, width, windowHeight), output); }
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(); if (!script.HasValue("searchpath")) script.SetObject("searchpath", Path.GetDirectoryName(args[0])); 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()); } } } }
static void Main(string[] args) { script = new Script(); Console.WriteLine("the current version : " + Script.Version); script.LoadLibrary(); script.PushAssembly(typeof(Program).GetTypeInfo().Assembly); #if !SCORPIO_NET_CORE string CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; #else string CurrentDirectory = ""; #endif 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()); } } } }
private void Run_Click(object sender, EventArgs e) { Script script = new Script(); try { m_txtBuildOutput.Text = ""; m_txtScriptOutput.Text = ""; script.LoadLibrary(); script.PushAssembly(GetType().Assembly); Stopwatch watch = Stopwatch.StartNew(); script.SetObject("print", new ScorpioFunction(print)); BuildOutPut("返回值为 " + script.LoadString(textBox1.Text)); BuildOutPut("运行时间:" + watch.ElapsedMilliseconds + " ms"); } catch (System.Exception ex) { BuildOutPut("堆栈数据为 " + script.GetStackInfo()); BuildOutPut(ex.ToString()); } }