1 Star 0 Fork 0

codes_test/RustPython

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
lib.rs 861 Bytes
一键复制 编辑 原始数据 按行查看 历史
rmliddle 提交于 2018-10-28 10:30 +08:00 . formatting fixes
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 here
log("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"),
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/codes_test/RustPython.git
git@gitee.com:codes_test/RustPython.git
codes_test
RustPython
RustPython
framestack

搜索帮助