Beispiel #1
0
        /// <summary>
        /// Creates a new ScriptRuntime with the IronPython scripting engine pre-configured
        /// in the specified AppDomain.  The remote ScriptRuntime may  be manipulated from
        /// the local domain but all code will run in the remote domain.
        /// </summary>
        public static ScriptRuntime /*!*/ CreateRuntime(AppDomain /*!*/ domain)
        {
            ContractUtils.RequiresNotNull(domain, "domain");

            return(ScriptRuntime.CreateRemote(domain, CreateRuntimeSetup(null)));
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new ScriptRuntime with the IronPython scripting engine pre-configured
        /// in the specified AppDomain with additional options.  The remote ScriptRuntime may
        /// be manipulated from the local domain but all code will run in the remote domain.
        /// </summary>
        public static ScriptRuntime /*!*/ CreateRuntime(AppDomain /*!*/ domain, IDictionary <string, object> options)
        {
            ContractUtils.RequiresNotNull(domain, nameof(domain));

            return(ScriptRuntime.CreateRemote(domain, CreateRuntimeSetup(options)));
        }
Beispiel #3
0
        public Ruby()
        {
            //Setup the script engine runtime
            var setup = new ScriptRuntimeSetup();

            setup.LanguageSetups.Add(
                new LanguageSetup(
                    "IronRuby.Runtime.RubyContext, IronRuby",
                    "IronRuby 1.0",
                    new[] { "IronRuby", "Ruby", "rb" },
                    new[] { ".rb" }));
            setup.DebugMode = true;

            //Create the runtime, engine, and scope
            runtime = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, setup);
            engine  = runtime.GetEngine("Ruby");
            scope   = engine.CreateScope();

            try
            {
                engine.Execute(@"$RGSS_VERSION = " + Program.GetRuntime().GetRGSSVersion(), scope);
                engine.Execute(@"$GAME_DIRECTORY = '" + Program.GetRuntime().GetResourcePaths()[0].Replace(@"\", @"\\") + @"'", scope);
                engine.Execute(@"$GAME_OS_WIN = " + Program.GetRuntime().IsWindowsOS().ToString().ToLower(), scope);
            }
            catch (Exception e)
            {
                Program.Error(e.Message);
            }

            //Load system internals and our Ruby internals
            Console.WriteLine("Loading system");
            //engine.Execute(System.Text.Encoding.UTF8.GetString(Properties.Resources.System), scope);
            string script = System.Text.Encoding.UTF8.GetString(Properties.Resources.System);

            script = script.Substring(1);  //fix for a weird character that shouldn't be there o.O
            Eval(script);

            //Load the adaptable RPG datatypes
            script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG);
            script = script.Substring(1);
            Eval(script);

            //Load the version appropriate RPG datatypes
            if (Program.GetRuntime().GetRGSSVersion() == 1)
            {
                script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG1);
                script = script.Substring(1);
                Eval(script);
            }
            if (Program.GetRuntime().GetRGSSVersion() == 2)
            {
                script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG2);
                script = script.Substring(1);
                Eval(script);
            }
            if (Program.GetRuntime().GetRGSSVersion() == 3)
            {
                script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG3);
                script = script.Substring(1);
                Eval(script);
            }
        }
Beispiel #4
0
 internal static ScriptRuntime CreateRuntime(AppDomain appDomain)
 {
     return(ScriptRuntime.CreateRemote(appDomain, CreateSetup()));
 }
Beispiel #5
0
 public static ScriptRuntime CreateRemoteRuntime(AppDomain domain)
 {
     return(ScriptRuntime.CreateRemote(domain, CreateSetup()));
 }
Beispiel #6
0
        /// <summary>
        /// 主要函数 --- 哔哔哔
        /// </summary>
        public void StartScript()
        {
            Debug.LogError(Application.persistentDataPath);

            try
            {
                _scriptruntim = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, _setup);
                _ex          += "\n 创建ScriptRunTime成功";
            }
            catch (Exception e)
            {
                _ex += "\n 创建ScriptRuntime异常,ex:" + e;
                throw;
            }
            finally
            {
                InputField.text = _ex;
            }
            //            try
            //            {
            //                //_assembly = Assembly.GetAssembly(typeof(GameObject));
            //                //_scriptruntim.LoadAssembly(_assembly);
            //                //_ex += "\n 加载UnityEngine到ScriptRunTime成功,路径:\n \t" + _assembly.CodeBase;
            //
            //                _assembly = Assembly.GetAssembly(typeof(tt));
            //                _scriptruntim.LoadAssembly(_assembly);
            //
            //                _ex += "\n 加载Icarus.DLR.Test到ScriptRunTime成功,路径:\n \t" + _assembly.CodeBase;
            //
            //            }
            //            catch (Exception e)
            //            {
            //                _ex += "\n 加载UnityEngine到ScriptRunTime失败,ex:"+e;
            //            }
            //            finally
            //            {
            //                InputField.text = _ex;
            //            }
            try
            {
                _script = _scriptruntim.UseFile(_getPyPath(_getPersistentDataPath()));
                _ex    += "\n 加载脚本成功";
            }
            catch (Exception e)
            {
                _ex += "\n 打开脚本出现错误:" + e;
                throw;
            }
            finally
            {
                InputField.text = _ex;
            }
            try
            {
                _ex += "\n 获取变量 test:" + _script.test;
                _ex += "\n 脚本执行结束";
                ButtonObj.gameObject.SetActive(true);
                foreach (var ces in _script.clr.References)
                {
                    _ex += "\n 程序集:" + ces;
                }
            }
            catch (Exception e)
            {
                _ex += "\n 执行脚本出现错误:" + e;
                throw;
            }
            finally
            {
                InputField.text = _ex;
            }
        }