@@ -45,10 +45,6 @@ pub fn setup_console_error() {
4545 std:: panic:: set_hook ( Box :: new ( panic_hook) ) ;
4646}
4747
48- // Hack to comment out wasm-bindgen's generated typescript definitons
49- #[ wasm_bindgen( typescript_custom_section) ]
50- const TS_CMT_START : & ' static str = "/*" ;
51-
5248fn run_py ( source : & str , options : Option < Object > , mode : Mode ) -> Result < JsValue , JsValue > {
5349 let vm = VMStore :: init ( PY_EVAL_VM_ID . into ( ) , Some ( true ) ) ;
5450 let options = options. unwrap_or_else ( Object :: new) ;
@@ -70,7 +66,7 @@ fn run_py(source: &str, options: Option<Object>, mode: Mode) -> Result<JsValue,
7066 }
7167 vm. run ( source, mode)
7268}
73- # [ wasm_bindgen ( js_name = pyEval ) ]
69+
7470/// Evaluate Python code
7571///
7672/// ```js
@@ -87,12 +83,11 @@ fn run_py(source: &str, options: Option<Object>, mode: Mode) -> Result<JsValue,
8783/// - `stdout?`: `"console" | ((out: string) => void) | null`: A function to replace the
8884/// native print native print function, and it will be `console.log` when giving
8985/// `undefined` or "console", and it will be a dumb function when giving null.
90-
86+ # [ wasm_bindgen ( js_name = pyEval ) ]
9187pub fn eval_py ( source : & str , options : Option < Object > ) -> Result < JsValue , JsValue > {
9288 run_py ( source, options, Mode :: Eval )
9389}
9490
95- #[ wasm_bindgen( js_name = pyExec) ]
9691/// Evaluate Python code
9792///
9893/// ```js
@@ -102,11 +97,11 @@ pub fn eval_py(source: &str, options: Option<Object>) -> Result<JsValue, JsValue
10297/// `code`: `string`: The Python code to run in exec mode
10398///
10499/// `options`: The options are the same as eval mode
105- pub fn exec_py ( source : & str , options : Option < Object > ) {
106- let _ = run_py ( source, options, Mode :: Exec ) ;
100+ #[ wasm_bindgen( js_name = pyExec) ]
101+ pub fn exec_py ( source : & str , options : Option < Object > ) -> Result < ( ) , JsValue > {
102+ run_py ( source, options, Mode :: Exec ) . map ( drop)
107103}
108104
109- #[ wasm_bindgen( js_name = pyExecSingle) ]
110105/// Evaluate Python code
111106///
112107/// ```js
@@ -116,17 +111,7 @@ pub fn exec_py(source: &str, options: Option<Object>) {
116111/// `code`: `string`: The Python code to run in exec single mode
117112///
118113/// `options`: The options are the same as eval mode
114+ #[ wasm_bindgen( js_name = pyExecSingle) ]
119115pub fn exec_single_py ( source : & str , options : Option < Object > ) -> Result < JsValue , JsValue > {
120116 run_py ( source, options, Mode :: Single )
121117}
122-
123- #[ wasm_bindgen( typescript_custom_section) ]
124- const TYPESCRIPT_DEFS : & ' static str = r#"
125- */
126- export interface PyEvalOptions {
127- stdout: (out: string) => void;
128- vars: { [key: string]: any };
129- }
130-
131- export function pyEval(code: string, options?: PyEvalOptions): any;
132- "# ;
0 commit comments