Skip to content

Commit

Permalink
Set internal envelope (fixes #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Sep 2, 2024
1 parent 82ef6a3 commit 9b7ca5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
6 changes: 1 addition & 5 deletions src/runtime/actions/action_mime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,7 @@ impl ExtractText {
.insert(var_name.to_string().into(), value.into());
}
VariableType::Envelope(env) => {
ctx.queued_events = vec![Event::SetEnvelope {
envelope: *env,
value,
}]
.into_iter();
ctx.add_set_envelope_event(*env, value);
}
_ => (),
}
Expand Down
24 changes: 18 additions & 6 deletions src/runtime/actions/action_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::{
VariableType,
},
runtime::Variable,
Context, Event,
Context, Envelope, Event,
};
use std::fmt::Write;

Expand Down Expand Up @@ -69,16 +69,28 @@ impl<'x> Context<'x> {
.insert(var_name.to_string().into(), variable.clone());
}
VariableType::Envelope(env) => {
self.queued_events = vec![Event::SetEnvelope {
envelope: *env,
value: variable.to_string().into_owned(),
}]
.into_iter();
self.add_set_envelope_event(*env, variable.to_string().into_owned());
}
_ => (),
}
}

pub(crate) fn add_set_envelope_event(&mut self, envelope: Envelope, value: String) {
let mut did_find = false;
for (name, val) in self.envelope.iter_mut() {
if *name == envelope {
*val = Variable::String(value.clone().into());
did_find = true;
break;
}
}
if !did_find {
self.envelope
.push((envelope, Variable::String(value.clone().into())));
}
self.queued_events = vec![Event::SetEnvelope { envelope, value }].into_iter();
}

pub(crate) fn get_variable(&self, var_name: &VariableType) -> Option<&Variable> {
match var_name {
VariableType::Local(var_id) => self.vars_local.get(*var_id),
Expand Down

0 comments on commit 9b7ca5b

Please sign in to comment.