Skip to content

Commit

Permalink
Finally can call a Rust function from JS! #47
Browse files Browse the repository at this point in the history
  • Loading branch information
mverleg committed May 13, 2018
1 parent fa3c2a5 commit 543e60d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ These instructions were tested on Ubuntu 18.4 (using Bash). It should also work
.. code:: bash
cargo +nightly build --target wasm32-unknown-unknown --release
wasm-bindgen target/wasm32-unknown-unknown/release/mango.wasm --out-dir target/deploy/
wasm-bindgen --no-modules --no-typescript target/wasm32-unknown-unknown/release/mango.wasm --out-dir target/deploy/
# then open target/deploy/index.html in a browser
* You're now ready to make changes! If you want to help, you're very welcome! Have a glance at CONTRIBUTING.rst_ if you have a minute.
Expand Down
16 changes: 0 additions & 16 deletions src/mango/ui/webi/compile_str.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
//use std::ffi::CStr;
//use std::ffi::CString;
//use std::os::raw::c_char;
use wasm_bindgen::prelude::*;

//// Convert a c-string, e.g. from javascript, into a Rust String.
//fn str_to_rust(external_str: *const c_char) -> String {
// unsafe { CStr::from_ptr(external_str).to_string_lossy().into_owned() }
//}
//
//// Convert a Rust string into a c-string.
//fn str_from_rust(internal_str: String) -> *mut c_char {
// CString::new(internal_str.as_str()).unwrap().into_raw()
//}

#[wasm_bindgen]
pub fn compile_string_to_wat(code: &str) -> String {
// let code = str_to_rust(codechrs);
// TODO
println!("compiling {}", code);
format!("compiled: {}", code).to_owned()
// str_from_rust(code)
}
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h1>Mango (wasm)</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.3.3/theme-crimson_editor.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.3.3/mode-javascript.js"></script>

<script>
<script type="application/javascript">
let editor = ace.edit("editor");
editor.setTheme("ace/theme/crimson_editor");
editor.session.setMode("ace/mode/javascript");
Expand Down

0 comments on commit 543e60d

Please sign in to comment.