1
0
mirror of synced 2024-11-14 11:07:43 +01:00

fix: Always evaluate in/out variables correctly

Fixes #629
This commit is contained in:
WerWolv 2022-08-02 23:36:18 +02:00
parent 6de00b3a6a
commit 1d9e8dbda7
2 changed files with 26 additions and 35 deletions

View File

@ -100,7 +100,6 @@ namespace hex::plugin::builtin {
void drawPatternTooltip(pl::Pattern *pattern);
void loadPatternFile(const std::fs::path &path);
void clearPatterns();
void parsePattern(const std::string &code);
void evaluatePattern(const std::string &code);

View File

@ -345,9 +345,10 @@ namespace hex::plugin::builtin {
if (ImGui::IconButton(ICON_VS_DEBUG_STOP, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed)))
runtime.abort();
} else {
if (ImGui::IconButton(ICON_VS_DEBUG_START, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarGreen)))
if (ImGui::IconButton(ICON_VS_DEBUG_START, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarGreen))) {
this->evaluatePattern(this->m_textEditor.GetText());
}
}
ImGui::PopStyleVar();
@ -381,7 +382,7 @@ namespace hex::plugin::builtin {
if (this->m_runAutomatically)
this->evaluatePattern(this->m_textEditor.GetText());
else
this->parsePattern(this->m_textEditor.GetText());
std::thread([this, code = this->m_textEditor.GetText()] { this->parsePattern(code); }).detach();
}
}
@ -732,21 +733,11 @@ namespace hex::plugin::builtin {
this->evaluatePattern(code);
this->m_textEditor.SetText(code);
this->parsePattern(code);
std::thread([this, code] { this->parsePattern(code); }).detach();
}
}
void ViewPatternEditor::clearPatterns() {
if (!ImHexApi::Provider::isValid()) return;
ImHexApi::Provider::get()->getPatternLanguageRuntime().reset();
this->parsePattern("");
}
void ViewPatternEditor::parsePattern(const std::string &code) {
this->m_runningParsers++;
std::thread([this, code] {
auto ast = this->m_parserRuntime->parseString(code);
this->m_patternVariables.clear();
@ -776,7 +767,6 @@ namespace hex::plugin::builtin {
}
this->m_runningParsers--;
}).detach();
}
void ViewPatternEditor::evaluatePattern(const std::string &code) {
@ -793,6 +783,8 @@ namespace hex::plugin::builtin {
for (const auto &[id, name, value, type] : this->m_envVarEntries)
envVars.insert({ name, value });
this->parsePattern(code);
std::map<std::string, pl::Token::Literal> inVariables;
for (auto &[name, variable] : this->m_patternVariables) {
if (variable.inVariable)