extern crate rustpython_vm;extern crate wasm_bindgen;use rustpython_vm::compile;use rustpython_vm::VirtualMachine;use wasm_bindgen::prelude::*;#[wasm_bindgen]extern "C" {// Use `js_namespace` here to bind `console.log(..)` instead of just// `log(..)`#[wasm_bindgen(js_namespace = console)]fn log(s: &str);}#[wasm_bindgen]pub fn run_code(source: &str) -> () {//add hash in herelog("Running RustPython");log(&source.to_string());let mut vm = VirtualMachine::new();let code_obj = compile::compile(&mut vm, &source.to_string(), compile::Mode::Exec, None);let builtins = vm.get_builtin_scope();let vars = vm.context().new_scope(Some(builtins));match vm.run_code_obj(code_obj.unwrap(), vars) {Ok(_value) => log("Execution successful"),Err(_) => log("Execution failed"),}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。