Exemple #1
0
        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);
        }