Last active
May 12, 2021 21:05
-
-
Save jareddlc/7c2db101eb94dc2baa19fd955d554840 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
println!("{}", path); | |
let store = Store::default(); | |
let module = Module::from_file(&store, &path).expect("Failed to load module"); | |
let mut wasi_env = WasiState::new("Gut") | |
.finalize() | |
.expect("Failed to create wasi env"); | |
let import_object = wasi_env | |
.import_object(&module) | |
.expect("Failed to create import object"); | |
let instance = | |
Instance::new(&module, &import_object).expect("Failed to create instance"); | |
let start = instance | |
.exports | |
.get_function("gut_export_functions") | |
.unwrap(); | |
let res = start.call(&[]).unwrap(); |
This file contains hidden or 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
use std::ffi::CString; | |
use std::os::raw::c_char; | |
use std::time::{SystemTime, UNIX_EPOCH}; | |
#[no_mangle] | |
pub extern "C" fn gut_export_functions() -> *mut c_char { | |
let c_str_song = CString::new(r#"["time_now"]"#).unwrap(); | |
c_str_song.into_raw() | |
} | |
#[no_mangle] | |
pub extern "C" fn gut_export_descriptions() -> *mut c_char { | |
let c_str_song = CString::new(r#"["Prints the current time in milliseconds"]"#).unwrap(); | |
c_str_song.into_raw() | |
} | |
#[no_mangle] | |
fn time_now() { | |
let now = SystemTime::now(); | |
let epoch = now.duration_since(UNIX_EPOCH).expect("Failed to get time"); | |
println!("{}", epoch.as_millis()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment