static public void StartInitFlow() { BubConsole.CSay("Looking for Init script!"); var mainfile = ""; foreach (string e in SBubble.ResFiles) { var ce = e.ToUpper(); if (ce == "INIT.LUA" || qstr.Suffixed(ce, "/INIT.LUA") || ce == "INIT.NIL" || qstr.Suffixed(ce, "/INIT.NIL")) { mainfile = e; } } if (mainfile == "") { Error.GoError("Startup error", "INIT.LUA or INIT.NIL required somewhere in any folder.", "None have been found"); } else { //mainfile = "Script/Viezelul.lua"; GoHardFlow(BubConsole.Flow); try { BubConsole.WriteLine($"Loading Init Script: {mainfile}"); SBubble.NewState("$INIT", mainfile); //SBubble.State("$INIT").state.DoString("local fc = ''\nfor k,v in pairs(_G) do\n fc=fc .. type(v) .. ' ' ..k..'\\n'\n end\n error(fc)"); // debug line SBubble.State("$INIT").state.DoString("assert(type(Bubble_Init)=='function','Function expected for Bubble_Init, got '..type(Bubble_Init))\nBubble_Init()"); } catch (Exception e) { Error.GoError("Init Error", e.Message, ""); } } }
public void LoadState(string s, string file) { s = s.ToUpper(); if (qstr.Prefixed(s, "FLOW_")) { throw new Exception("Non-Flow states may NOT be prefixed with FLOW_"); } SBubble.NewState(s, file); SBubble.State(s).state.DoString("if BUB_Load then BUB_Load() end"); }
public void LoadFlow(string flow, string file) { flow = flow.ToUpper(); if (!qstr.Prefixed(flow, "FLOW_")) { flow = $"FLOW_{flow}"; } SBubble.NewState(flow, file); BubConsole.WriteLine($"Created new flow: {flow}"); SBubble.State(flow).state.DoString("if BUB_Load then BUB_Load() end"); }
static public void NewSoftFlow(string tag, string scriptfile) { //BubConsole.CSay($"Starting new state {tag} with script {scriptfile}"); tag = tag.ToUpper(); if (!qstr.Prefixed(tag, "FLOW_")) { tag = $"FLOW_{tag}"; } SBubble.NewState(tag, scriptfile); try { SBubble.State(tag).DoString($"(BUB_Load or {NOTHING})()", "LOAD"); } catch (Exception NotAnExceptionJustAnErrorBozos) { SBubble.MyError("Load Error", NotAnExceptionJustAnErrorBozos.Message, ""); } }
static void Main(string[] args) { JCR6_lzma.Init(); JCR6_zlib.Init(); JCR6_jxsrcca.Init(); SBubble.Init("CLI", ErrorHandler); var mainfile = ""; foreach (string e in SBubble.ResFiles) { var ce = e.ToUpper(); if (ce == "MAIN.LUA" || qstr.Suffixed(ce, "/MAIN.LUA")) { mainfile = e; } } if (mainfile == "") { ErrorHandler("Bubble", "No main script could be found", ""); } SBubble.NewState("MAIN", mainfile); object[] r = null; string cmd = ""; try { cmd = $"assert(main and type(main)==\"function\",\"No 'main' function found!\")\nreturn main({SBubble.StringArray2Lua(args)},\"{MKL.MyExe.Replace("\\", "/")}\")"; r = SBubble.State("MAIN").DoString(cmd); } catch (Exception e) { ErrorHandler("Main call", e.Message, cmd); } long exitcode = 0; try { if (r != null && r[0] != null) { exitcode = (long)(r[0]); } } catch (Exception e) { ErrorHandler("Main Function", "Main function must either return 'nil' or an integer value!", $"{e.Message}\n\n{r[0].GetType()}"); } Environment.Exit((int)exitcode); }
void Exe(string rawcmd) { rawcmd = rawcmd.Trim(); if (rawcmd == "") { return; } string[] chopped; { var chop = new List <string>(); var str = false; var s = ""; for (int i = 0; i < rawcmd.Length; i++) { switch (rawcmd[i]) { case '"': str = !str; break; case ' ': if (str) { goto default; // diryt way to fallthrough, but it's the only thing C# supports! } chop.Add(s); s = ""; break; default: s += rawcmd[i]; break; } } chop.Add(s); chopped = chop.ToArray(); } string cmd = chopped[0].ToUpper(); string[] arg = new string[0]; if (chopped.Length > 1) { arg = chopped.Skip(1).Take(chopped.Length - 1).ToArray(); } switch (cmd) { case "F**K": case "PISS": case "SHIT": WriteLine("?Did you mother never tell you not to say such words?", 255, 0, 0); break; case "BYE": case "EXIT": case "QUIT": FlowManager.TimeToDie = true; break; case "SAY": foreach (string a in arg) { CSay(a); } break; default: try { // Need to group as some extra vars are needed! { var CFlow = FlowManager.CurrentFlow; var FFlow = $"FLOW_{CFlow}"; var SFlow = SBubble.State(CFlow); var JArgs = ""; BubConsScriptSuccess = false; foreach (string a in arg) { if (JArgs != "") { JArgs += ", "; } JArgs += $"\"{a}\""; } // Execute local if available SFlow.DoString($"if not ConsoleCommands then ConsoleSuccess(false) return end\nif not ConsoleCommands['.hasmember']('{cmd}') then ConsoleSuccess(false) return end\nConsoleSuccess(true)\nConsoleCommands.{cmd}({JArgs})"); if (BubConsScriptSuccess) { break; // If done, get outta here } // Load the global commands if needed if (!SBubble.HaveState("DEBUG_CONSOLE_COMMANDS")) { WriteLine("Since this is the first time the Debug Console Commands are neeed", 255, 180, 0); WriteLine("The commands need to be loaded now, just a moment", 255, 180, 0); SBubble.NewState("DEBUG_CONSOLE_COMMANDS", "Script/System/Console.nil"); WriteLine("Ok", 0, 255, 255); } // Execute gloal SBubble.State("DEBUG_CONSOLE_COMMANDS").DoString($"if not ConsoleCommands then CSay('Hey buddy! No ConsoleCommands group exists!') ConsoleSuccess(false) return end\nif not ConsoleCommands['.hasmember']('{cmd}') then ConsoleSuccess(false) return end\nConsoleSuccess(true)\nConsoleCommands.{cmd}({JArgs})"); if (BubConsScriptSuccess) { break; // If done, get outta here } } // Failure, or so it seems. WriteLine("?Not understood", 255, 0, 0); } catch (Exception NietGoed) { WriteLine("?.NET error", 255, 0, 0); WriteLine($" {NietGoed.Message}", 255, 255, 0); } break; } }