/// <summary> /// Runs the compiler hook/function call on the compiler languge binding class. /// </summary> /// <param name="objectName"></param> /// <param name="method"></param> /// <param name="settings"></param> /// <param name="expr"></param> /// <returns></returns> private object RunCompilerMethod(string objectName, string method, LangSettings settings, FunctionCallExpr expr) { var binding = new MetaCompiler(); binding.Ctx = expr.Ctx; binding.ExecuteFunction(method, new object[] { expr }); return(LObjects.Null); }
/// <summary> /// Logs severity to console. /// </summary> /// <param name="settings">Settings for interpreter</param> /// <param name="exp">The functiona call expression</param> public static string Log(LangSettings settings, FunctionCallExpr exp) { if (!settings.EnableLogging) { return(string.Empty); } var funcname = exp.ToQualifiedName(); var severity = funcname.Substring(funcname.IndexOf(".") + 1); var message = BuildMessage(exp.ParamList); Console.WriteLine(severity.ToUpper() + " : " + message); return(message); }
/// <summary> /// Initialize /// </summary> public Interpreter() { _settings = new LangSettings(); // Initialzie the context. _context = new Context(); _context.Settings = _settings; _context.Limits.Init(); _memory = _context.Memory; _parser = new Parser(_context); _parser.Settings = _settings; InitSystemFunctions(); }
/// <summary> /// Prints to the console. /// </summary> /// /// <param name="settings">Settings for interpreter</param> /// <param name="exp">The functiona call expression</param> /// <param name="printline">Whether to print with line or no line</param> public static string Print(LangSettings settings, FunctionCallExpr exp, bool printline) { if (!settings.EnablePrinting) { return(string.Empty); } string message = BuildMessage(exp.ParamList); if (printline) { Console.WriteLine(message); } else { Console.Write(message); } return(message); }
public static void Main(string[] args) { try // last-resort try/catch block { #if !DEBUG // unless debugging, handle all thread exceptions Application.ThreadException += Application_ThreadException; #endif // get language LangSettings lang = new LangSettings(); lang.LoadFromRegistry(); string langLogError = null, langLogEntry = null; uiCulture = Thread.CurrentThread.CurrentUICulture; try { uiCulture = new CultureInfo(lang.langCode); Thread.CurrentThread.CurrentUICulture = uiCulture; langLogEntry = String.Format("Setting language to {0}", uiCulture.EnglishName); } catch (Exception ex) { langLogError = String.Format("Failed to set language: {0}", ex.Message); } // get app version info version = Assembly.GetExecutingAssembly().GetName().Version; versionString = Misc.VersionToString(version); // require win2k or greater, due to: // - GetLastInputInfo // - CredUIConfirmCredentials if (Environment.OSVersion.Version.Major < 5) { MessageBox.Show(Language.Error_WindowsVersion, Language.Error_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // perform basic dupe process detection #if !MAC if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1) { // make sure we're not just waiting for ourself to exit after changing to/from sleep mode Thread.Sleep(2000); if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1) { MessageBox.Show(Language.Error_AlreadyRunning, Language.Error_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } #endif // process command-line arguments bool argSleep = false; if (args.Length >= 1 && args[0] == "sleep") { argSleep = true; } bool argAutowakeup = false; if (argSleep && args.Length >= 2 && args[1] == "autowakeup") { argAutowakeup = true; } bool argMinimised = false; if (args.Length >= 1 && args[0] == "minimised") { argMinimised = true; } // init log to file (will append if changing sleep <=> running) Log.OnNewLogEntry += Log.WriteToFile("BEGameMonitor.log"); if (langLogError != null) { Log.AddError(langLogError); } else if (langLogEntry != null) { Log.AddEntry(langLogEntry); } // make it pretty Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // if sleep arg, do sleep mode instead if (argSleep) { Log.AddEntry("In sleep mode (autowakeup {0})", argAutowakeup ? "on" : "off"); new SleepTrayIcon(argAutowakeup); Application.Run(); return; } // create game status window gameStatus = new GameStatus(); // manually hide tary icon on app exit (tends to hang around until mouseover sometimes?!?) Application.ApplicationExit += Application_ApplicationExit; // make sure windows set to default dpi for now (otherwise will draw everything screwy) // TODO: make dpi independant? System.Drawing.Graphics g = gameStatus.CreateGraphics(); int screenDpi = (int)g.DpiX; g.Dispose(); if (screenDpi != 96) { MessageBox.Show(String.Format(Language.Error_NonDefaultDPI, screenDpi), Language.Error_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); gameStatus.trayIcon.Visible = false; return; } // trick to force handle creation before Show()ing the form (to allow Invoke() to be called) IntPtr handle = gameStatus.Handle; // start initialisation in background, show the gui if necessary, and start the message loop gameStatus.Init(); if (gameStatus.options.Startup.startMinimised || argMinimised) { } // start minimised else { gameStatus.ShowWindow(); } Application.Run(); } #if DEBUG catch { throw; }