/// <summary> /// Call a hooked lua function. /// <para/> /// If you want to pass in a single array and want to access it in a single parameter in lua, convert it to a List first: /// <para/> /// C#: runner.Execute("func", List<string>); /// <para/> /// Lua: function func(list) /// </summary> /// <param name="hookName"></param> /// <param name="args"></param> public void Execute(string hookName, params object[] args) { try { foreach (var script in GlobalScripts.Values) { runningScript = script; script.GetHook(hookName)?.Execute(args); //RunLua(script, hookName, args); runningScript = null; } if (CurrentTempScript != null) { runningScript = CurrentTempScript; CurrentTempScript.GetHook(hookName)?.Execute(args); //RunLua(CurrentTempScript, hookName, args); runningScript = null; } } catch (Exception ex) { if (ex is InterpreterException e) { throw new Exception(e.DecoratedMessage); } throw ex; } finally { runningScript = null; } }
public void Reset() { foreach (var scr in GlobalScripts) { scr.Value.ResetHooks(); } GlobalScripts.Clear(); CurrentTempScript = null; Initialize(); }
void MakeGlobal(string name) { if (runningScript == null) { return; } if (!GlobalScripts.ContainsKey(name)) { //Unique global scripts GlobalScripts[name] = runningScript; } CurrentTempScript = null; //Remove temp so as to not dupe either way }
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; } }
public void ResetCurrent() { CurrentTempScript = null; }