LoadLibrary() 공개 메소드

public LoadLibrary ( ) : void
리턴 void
예제 #1
0
 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);
 }
예제 #3
0
 //解析文件结构
 private void ParseLayout()
 {
     mFields.Clear();
     mUsedCustoms.Clear();
     for (int i = 0; i < mMaxColumn; ++i)
     {
         PackageField field = new PackageField();
         field.Index   = i;
         field.Comment = mDataTable[0][i];            //第0行是注释
         field.Name    = mDataTable[1][i];            //第1行是字段名
         field.Default = mDataTable[3][i];            //第3行是字段默认值
         var            attribute = mDataTable[2][i]; //第2行是字段属性
         Scorpio.Script script    = new Scorpio.Script();
         script.LoadLibrary();
         if (string.IsNullOrEmpty(attribute))
         {
             field.Attribute = script.CreateTable();
         }
         else
         {
             field.Attribute = (script.LoadString("return {" + attribute + "}") as ScriptTable) ?? script.CreateTable();
         }
         string columnType = mDataTable[4][i];   //第4行是字段类型
         string fieldType  = "";
         if (columnType.StartsWith(Util.ArrayString))
         {
             field.Array = true;
             int iFinalIndex = Util.ArrayString.Length;
             fieldType = columnType.Substring(iFinalIndex, columnType.Length - iFinalIndex);
         }
         else
         {
             field.Array = false;
             fieldType   = columnType;
         }
         field.Type = fieldType;
         bool basic = BasicUtil.HasType(fieldType);
         if (!basic && !mCustoms.ContainsKey(fieldType) && !mEnums.ContainsKey(fieldType))
         {
             throw new System.Exception(string.Format("第[{0}]列的 字段类型[{1}] 不能识别", Util.GetLineName(i), columnType));
         }
         if (i == 0 && (field.Array == true || field.Info.BasicIndex != BasicEnum.INT32))
         {
             throw new System.Exception("第一列的数据类型必须为int32类型");
         }
         field.Enum = mEnums.ContainsKey(fieldType);
         //保存使用的自定义结构
         if (!basic && !field.Enum && !mUsedCustoms.Contains(fieldType))
         {
             mUsedCustoms.Add(fieldType);
         }
         mFields.Add(field);
     }
     if (mFields.Count == 0)
     {
         throw new System.Exception("字段个数为0");
     }
     mKeyName = mFields[0].Name;
 }
예제 #4
0
 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());
             }
         }
     }
 }
예제 #5
0
        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());
                    }
                }
            }
        }
예제 #6
0
 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());
     }
 }