Esempio n. 1
0
        private Script Inject(Script script, Action <ParserException> callback)
        {
            try {
                script.Options.ScriptLoader = this.loader;
                script.DebuggerEnabled      = true;
                script.Options.DebugPrint   = s => { Console.WriteLine(s); };
                UserData.RegistrationPolicy = InteropRegistrationPolicy.Automatic;
                UserData.RegisterType <TheSim>(InteropAccessMode.Reflection, "TheSim");
                TheSim sim = new TheSim();
                UserData.RegisterAssembly();

                script.Globals["TheSim"] = UserData.Create(sim);
            } catch (ScriptRuntimeException e) {
                ParserException exception;

                if (this.lua == null)
                {
                    exception = new ParserException(e, lua);
                }
                else
                {
                    exception = new ParserException(e, this.lua + "\n\n" + lua);
                }

                callback?.Invoke(exception);
                Boot.Core.IDE.GetDebugPanel().AddError(exception);
            } catch (SyntaxErrorException e) {
                ParserException exception;

                if (this.lua == null)
                {
                    exception = new ParserException(e, lua);
                }
                else
                {
                    exception = new ParserException(e, this.lua + "\n\n" + lua);
                }

                callback?.Invoke(exception);
                Boot.Core.IDE.GetDebugPanel().AddError(exception);
            } catch (InternalErrorException e) {
                ParserException exception;

                if (this.lua == null)
                {
                    exception = new ParserException(e, lua);
                }
                else
                {
                    exception = new ParserException(e, this.lua + "\n\n" + lua);
                }

                callback?.Invoke(exception);
                Boot.Core.IDE.GetDebugPanel().AddError(exception);
            } catch (InterpreterException e) {
                ParserException exception;

                if (this.lua == null)
                {
                    exception = new ParserException(e, lua);
                }
                else
                {
                    exception = new ParserException(e, this.lua + "\n\n" + lua);
                }

                callback?.Invoke(exception);
                Boot.Core.IDE.GetDebugPanel().AddError(exception);
            }
            return(script);
        }
Esempio n. 2
0
        public Script Run(string lua, Boolean injector, Action <ParserException> callback)
        {
            try {
                Script script = new Script();

                if (injector)
                {
                    script = this.Inject(script, callback);
                }

                if (this.lua == null || !injector)
                {
                    script.DoString(lua);
                }
                else
                {
                    script.DoString(this.lua + "\n\n" + lua);
                }

                return(script);
            } catch (ScriptRuntimeException e) {
                ParserException exception;

                if (this.lua == null)
                {
                    exception = new ParserException(e, lua);
                }
                else
                {
                    exception = new ParserException(e, this.lua + "\n\n" + lua);
                }

                callback?.Invoke(exception);
                Boot.Core.IDE.GetDebugPanel().AddError(exception);
            } catch (SyntaxErrorException e) {
                ParserException exception;

                if (this.lua == null)
                {
                    exception = new ParserException(e, lua);
                }
                else
                {
                    exception = new ParserException(e, this.lua + "\n\n" + lua);
                }

                callback?.Invoke(exception);
                Boot.Core.IDE.GetDebugPanel().AddError(exception);
            } catch (InternalErrorException e) {
                ParserException exception;

                if (this.lua == null)
                {
                    exception = new ParserException(e, lua);
                }
                else
                {
                    exception = new ParserException(e, this.lua + "\n\n" + lua);
                }

                callback?.Invoke(exception);
                Boot.Core.IDE.GetDebugPanel().AddError(exception);
            } catch (InterpreterException e) {
                ParserException exception;

                if (this.lua == null)
                {
                    exception = new ParserException(e, lua);
                }
                else
                {
                    exception = new ParserException(e, this.lua + "\n\n" + lua);
                }

                callback?.Invoke(exception);
                Boot.Core.IDE.GetDebugPanel().AddError(exception);
            }

            return(null);
        }