コード例 #1
0
        public void RunScript(string source)
        {
            _activeProcessorCount++;

            Task.Run(() =>
            {
                try
                {
                    var processor = CreateProcessor();
                    var result    = processor.Run(source);

                    if (ScriptContextManipulator.ThrownRuntimeError(processor) &&
                        ScriptOutAdapter.Translate(result) is ScriptRuntimeException runtimeException)
                    {
                        throw runtimeException;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("An error occurred during script execution: " + ex.Message);
                }

                _activeProcessorCount--;
            });
        }
コード例 #2
0
        public static void RunScript(string scriptFile)
        {
            if (_apiClasses == null)
            {
                InitializeApiClasses();
            }
            if (_prototypeBuffer == null)
            {
                InitializePrototypeBuffer();
            }

            ActiveProcessorCount++;
            Task.Run(() =>
            {
                try
                {
                    var gamemode = GameInstance.GetService <GameModeManager>().ActiveGameMode;
                    var source   = Encoding.UTF8.GetString(gamemode.FileLoader.GetFile(gamemode.GetScriptFilePath(scriptFile), false).Data);

                    var processor = CreateProcessor();
                    var result    = processor.Run(source);

                    if (ScriptContextManipulator.ThrownRuntimeError(processor))
                    {
                        var exObj = ScriptOutAdapter.Translate(result);

                        var runtimeException = exObj as ScriptRuntimeException;
                        if (runtimeException != null)
                        {
                            throw runtimeException;
                        }
                    }
                }
                catch (ArgumentNullException)
                {
                    var message = $"Failed to run script \"{scriptFile}\"";
                    GameLogger.Instance.Log(MessageType.Error, message);
                    GameInstance.GetService <NotificationBar>().PushNotification(NotificationKind.Error, message);
                }
                catch (ScriptRuntimeException ex)
                {
                    var message = $"Script execution failed at runtime. {ex.Type} ({scriptFile}, L{ex.Line}): {ex.Message}";
                    GameLogger.Instance.Log(MessageType.Error, message);
                    GameInstance.GetService <NotificationBar>().PushNotification(NotificationKind.Error, message);
                }

                ActiveProcessorCount--;
            });
        }