Develop wasm support further.
This commit is contained in:
@@ -15,6 +15,7 @@ crate-type = ["cdylib"]
|
||||
hel = { version = "0.1.0", path = "../hel" }
|
||||
lazy_static = "1.4.0"
|
||||
wasm-bindgen = "0.2.83"
|
||||
parking_lot = "0.12.1"
|
||||
|
||||
[dependencies.web-sys]
|
||||
version = "0.3.4"
|
||||
|
||||
+3
-2
@@ -76,8 +76,6 @@
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module">
|
||||
import init, { ok_add } from "./pkg/helwasm.js";
|
||||
|
||||
function read_line(prompt) {
|
||||
console.log("called read_line: " + prompt);
|
||||
return "line";
|
||||
@@ -88,9 +86,12 @@
|
||||
return "password";
|
||||
}
|
||||
|
||||
import init, { ok_add, hel_init, hel_command } from "./pkg/helwasm.js";
|
||||
init().then(() => {
|
||||
window.hel = {
|
||||
ok_add: ok_add,
|
||||
hel_init: hel_init,
|
||||
hel_command: hel_command,
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
use hel::lk::LK;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use hel::lk::{LK, LKRef};
|
||||
use hel::repl::LKRead;
|
||||
use hel::utils::editor::Editor;
|
||||
use std::sync::Arc;
|
||||
use parking_lot::ReentrantMutex;
|
||||
use std::cell::RefCell;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
lazy_static! {
|
||||
static ref STATE: Arc<Mutex<LK>> = Arc::new(Mutex::new(LK::new()));
|
||||
static ref STATE: LKRef = Arc::new(ReentrantMutex::new(RefCell::new(LK::new())));
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn hel_command(cmd: String) -> String {
|
||||
let editor = Editor::new();
|
||||
let mut lkread = LKRead::new(editor, "> ".to_string(), STATE.clone());
|
||||
lkread.cmd = cmd.to_string();
|
||||
let lkeval = lkread.read();
|
||||
let lkprint = lkeval.eval();
|
||||
lkprint.out.output().join("\n")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user