MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / execute_code

Method execute_code

aiscript/src/repr.rs:146–170  ·  view source on GitHub ↗
(&mut self, code: &str)

Source from the content-addressed store, hash-verified

144 }
145
146 fn execute_code(&mut self, code: &str) -> Result<(), VmError> {
147 // Wrap the code in a function if it's an expression
148 let code = if !code.contains(';') && !code.contains("fn ") && !code.contains("class ") {
149 format!("return {};", code)
150 } else {
151 code.to_string()
152 };
153
154 match self.vm.compile(Box::leak(code.into_boxed_str())) {
155 Ok(()) => {
156 match self.vm.interpret() {
157 Ok(value) => {
158 // Only print non-nil values
159 if !matches!(value, ReturnValue::Nil) {
160 println!("{}", value);
161 }
162 }
163 Err(e) => eprintln!("Runtime error: {}", e),
164 }
165 }
166 Err(e) => eprintln!("Compile error: {}", e),
167 }
168
169 Ok(())
170 }
171}

Callers 1

runMethod · 0.80

Calls 3

containsMethod · 0.80
compileMethod · 0.80
interpretMethod · 0.80

Tested by

no test coverage detected