pub struct Interpreter { /* private fields */ }Expand description
The FiddlerScript interpreter.
Implementations§
Source§impl Interpreter
impl Interpreter
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new interpreter with default built-in functions.
The interpreter is initialized with all current OS environment variables available as script variables.
Sourcepub fn with_builtins(
builtins: HashMap<String, fn(Vec<Value>) -> Result<Value, RuntimeError>>,
) -> Self
pub fn with_builtins( builtins: HashMap<String, fn(Vec<Value>) -> Result<Value, RuntimeError>>, ) -> Self
Create a new interpreter with custom built-in functions.
The interpreter is initialized with all current OS environment variables available as script variables.
Sourcepub fn new_without_env() -> Self
pub fn new_without_env() -> Self
Create a new interpreter without loading environment variables.
Sourcepub fn parse_only(&self, source: &str) -> Result<Program, FiddlerError>
pub fn parse_only(&self, source: &str) -> Result<Program, FiddlerError>
Parse FiddlerScript source without executing it.
Identical to crate::parse but provided as a method for API symmetry
with Interpreter::run.
Sourcepub fn run(&mut self, source: &str) -> Result<Value, FiddlerError>
pub fn run(&mut self, source: &str) -> Result<Value, FiddlerError>
Run FiddlerScript source code.
Sourcepub fn execute(&mut self, program: &Program) -> Result<Value, RuntimeError>
pub fn execute(&mut self, program: &Program) -> Result<Value, RuntimeError>
Execute a parsed program.
Sourcepub fn clear_output(&mut self)
pub fn clear_output(&mut self)
Clear captured output.
Sourcepub fn is_output_truncated(&self) -> bool
pub fn is_output_truncated(&self) -> bool
Check if captured output was truncated.
Sourcepub fn set_variable_value(&mut self, name: impl Into<String>, value: Value)
pub fn set_variable_value(&mut self, name: impl Into<String>, value: Value)
Set a variable by name in the global scope.
This allows external code to inject values into the interpreter before running a script.
§Arguments
name- The variable namevalue- The value to set
Sourcepub fn set_variable_bytes(&mut self, name: impl Into<String>, bytes: Vec<u8>)
pub fn set_variable_bytes(&mut self, name: impl Into<String>, bytes: Vec<u8>)
Set a variable from bytes.
Convenience method to set a variable with byte data.
§Arguments
name- The variable namebytes- The byte data
Sourcepub fn set_variable_string(
&mut self,
name: impl Into<String>,
value: impl Into<String>,
)
pub fn set_variable_string( &mut self, name: impl Into<String>, value: impl Into<String>, )
Set a variable from a string.
Convenience method to set a variable with string data.
§Arguments
name- The variable namevalue- The string value
Sourcepub fn set_variable_int(&mut self, name: impl Into<String>, value: i64)
pub fn set_variable_int(&mut self, name: impl Into<String>, value: i64)
Set a variable from an integer.
Convenience method to set a variable with an integer value.
§Arguments
name- The variable namevalue- The integer value
Sourcepub fn set_variable_array(
&mut self,
name: impl Into<String>,
values: Vec<Value>,
)
pub fn set_variable_array( &mut self, name: impl Into<String>, values: Vec<Value>, )
Set a variable as an array.
Convenience method to set a variable with an array value.
§Arguments
name- The variable namevalues- The array values
Sourcepub fn set_variable_dict(
&mut self,
name: impl Into<String>,
values: IndexMap<String, Value>,
)
pub fn set_variable_dict( &mut self, name: impl Into<String>, values: IndexMap<String, Value>, )
Set a variable as a dictionary.
Convenience method to set a variable with a dictionary value.
§Arguments
name- The variable namevalues- The dictionary values