-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to bindgen without emscripten for library-mode #47
- Loading branch information
Showing
6 changed files
with
32 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
use std::ffi::CStr; | ||
use std::ffi::CString; | ||
use std::os::raw::c_char; | ||
//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() | ||
} | ||
//// 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() | ||
//} | ||
|
||
#[no_mangle] | ||
pub fn compile_string_to_wat(codechrs: *const c_char) -> *mut c_char { | ||
let code = str_to_rust(codechrs); | ||
#[wasm_bindgen] | ||
pub fn compile_string_to_wat(code: &str) -> String { | ||
// let code = str_to_rust(codechrs); | ||
// TODO | ||
println!("compiling {}", code); | ||
str_from_rust(code) | ||
format!("compiled: {}", code).to_owned() | ||
// str_from_rust(code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters