public void LoadScript(string scriptString, string scriptName = "User Code")
        {
            //Remove old hooks so they aren't counted
            if (ScriptStandard != null)
            {
                ScriptStandard.Scrub(Lua, scriptContainer);
            }

            scriptContainer.ResetHooks();

            Lua.DoString(scriptString, null, scriptName);

            if (ScriptStandard != null)
            {
                List <string> errors = new List <string>();
                bool          res    = ScriptStandard.ApplyStandard(Lua, scriptContainer, errors);
                if (!res)
                {
                    //Todo: new type of exception with info
                    throw new Exception($"Script Standard was not met! Standards Not Met: [{string.Join(", ", errors)}]");
                }
            }
        }
Example #2
0
        public void LoadScript(string scriptString)
        {
            //Remove old hooks so they aren't counted
            if (ScriptStandard != null)
            {
                ScriptStandard.Scrub(Lua, CurrentTempScript);
            }

            CurrentTempScript?.ResetHooks();


            if (string.IsNullOrWhiteSpace(scriptString))
            {
                //No script
                CurrentTempScript = null;
                return;
            }
            var scr = new HookedScriptContainer();

            CurrentTempScript = scr;

            runningScript = scr;
            try
            {
                Lua.DoString(scriptString);

                if (ScriptStandard != null)
                {
                    List <string> errors = new List <string>();
                    bool          res    = ScriptStandard.ApplyStandard(Lua, scr, errors);
                    if (!res)
                    {
                        throw new Exception($"Script Standard was not met! Standards Not Met: [{string.Join(", ", errors)}]");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                runningScript = null;
            }
        }