/// <summary> /// Looks up a global variable. If the variable is not defined in the /// global scope then built-ins is consulted. /// </summary> internal bool TryLookupBuiltin(string name, out object value) { object builtins; if (!GlobalDict.TryGetValue("__builtins__", out builtins)) { value = null; return(false); } PythonModule builtinsScope = builtins as PythonModule; if (builtinsScope != null && builtinsScope.__dict__.TryGetValue(name, out value)) { return(true); } PythonDictionary dict = builtins as PythonDictionary; if (dict != null && dict.TryGetValue(name, out value)) { return(true); } value = null; return(false); }
public int GetRefreshInterval() { if (GlobalDict.ContainsKey("interval")) { return(int.Parse(GlobalDict["interval"])); } else { return(30); // 默认半小时刷新一次 } }
public long GetVersion() { if (GlobalDict.ContainsKey("GlobalDict")) { return(long.Parse(GlobalDict["GlobalDict"])); } else { return(0); } }
public void ResetMacroDict(MacroType type) { switch (type) { case MacroType.Global: GlobalDict.Clear(); break; case MacroType.Local: LocalDict.Clear(); break; default: throw new CriticalErrorException($"Invalid MacroType {type}"); } }
/// <summary> /// Removes a variable from the global scope. /// </summary> internal bool TryRemoveGlobalVariable(string name) { return(GlobalDict.Remove(name)); }
/// <summary> /// Sets a variable in the global scope. /// </summary> internal void SetGlobalVariable(string name, object value) { GlobalDict.Add(name, value); }
/// <summary> /// Gets a variable from the global scope. /// </summary> internal bool TryGetGlobalVariable(string name, out object res) { return(GlobalDict.TryGetValue(name, out res)); }
public LogInfo SetMacro(string macroName, string macroCommand, ScriptSection section, bool global, bool permanent) { // Macro Name Validation if (!Regex.Match(macroName, MacroNameRegex, RegexOptions.Compiled | RegexOptions.CultureInvariant).Success) { return(new LogInfo(LogState.Error, $"Invalid macro name [{macroName}]")); } if (macroCommand != null) { // Insert // Try parsing CodeParser parser = new CodeParser(section, Global.Setting, section.Project.Compat); CodeCommand cmd = parser.ParseStatement(macroCommand); if (cmd.Type == CodeType.Error) { CodeInfo_Error info = cmd.Info.Cast <CodeInfo_Error>(); return(new LogInfo(LogState.Error, info.ErrorMessage)); } // Put into dictionary if (permanent) // MacroDict { GlobalDict[macroName] = cmd; if (IniReadWriter.WriteKey(section.Project.MainScript.RealPath, ScriptSection.Names.Variables, macroName, cmd.RawCode)) { return(new LogInfo(LogState.Success, $"Permanent Macro [{macroName}] set to [{cmd.RawCode}]")); } else { return(new LogInfo(LogState.Error, $"Could not write macro into [{section.Project.MainScript.RealPath}]")); } } if (global) // MacroDict { GlobalDict[macroName] = cmd; return(new LogInfo(LogState.Success, $"Global Macro [{macroName}] set to [{cmd.RawCode}]")); } LocalDict[macroName] = cmd; return(new LogInfo(LogState.Success, $"Local Macro [{macroName}] set to [{cmd.RawCode}]")); } else { // Delete // Put into dictionary if (permanent) // MacroDict { if (GlobalDict.ContainsKey(macroName)) { GlobalDict.Remove(macroName); IniReadWriter.DeleteKey(section.Project.MainScript.RealPath, ScriptSection.Names.Variables, macroName); return(new LogInfo(LogState.Success, $"Permanent Macro [{macroName}] deleted")); } return(new LogInfo(LogState.Error, $"Permanent Macro [{macroName}] not found")); } if (global) // MacroDict { if (GlobalDict.ContainsKey(macroName)) { GlobalDict.Remove(macroName); return(new LogInfo(LogState.Success, $"Global Macro [{macroName}] deleted")); } return(new LogInfo(LogState.Error, $"Global Macro [{macroName}] not found")); } // LocalDict if (LocalDict.ContainsKey(macroName)) { LocalDict.Remove(macroName); return(new LogInfo(LogState.Success, $"Local Macro [{macroName}] deleted")); } return(new LogInfo(LogState.Error, $"Local Macro [{macroName}] not found")); } }
internal bool TryRemoveGlobalVariable(string name) => GlobalDict.Remove(name);
internal bool TryGetGlobalVariable(string name, out object?res) => GlobalDict.TryGetValue(name, out res);