add e to calculator plugin, and fix a NPE for debugging

Co-Authored-By: Pavel Zwerschke <pavelzw@gmail.com>
This commit is contained in:
弘韬 张 2021-02-26 16:20:47 +08:00
parent 890f114931
commit cef09b3ee2

View file

@ -32,7 +32,13 @@ namespace Flow.Launcher.Plugin.Caculator
static Main()
{
MagesEngine = new Engine();
MagesEngine = new Engine(new Configuration
{
Scope = new Dictionary<string, object>
{
{ "e", Math.E }, // e is not contained in the default mages engine
}
});
}
public void Init(PluginInitContext context)
@ -55,7 +61,7 @@ namespace Flow.Launcher.Plugin.Caculator
var expression = query.Search.Replace(",", ".");
var result = MagesEngine.Interpret(expression);
if (result.ToString() == "NaN")
if (result?.ToString() == "NaN")
result = Context.API.GetTranslation("flowlauncher_plugin_calculator_not_a_number");
if (result is Function)