1
1
mirror of https://github.com/tweag/nickel.git synced 2024-09-21 00:19:57 +03:00

Add getters and setters, borrow the REPL on input

This commit is contained in:
Yann Hamdaoui 2021-04-20 13:12:49 +02:00
parent 93f8a61176
commit 3d2755aba0

View File

@ -617,6 +617,7 @@ pub mod simple_frontend {
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Clone, Copy, Eq, PartialEq)]
pub enum WASMResultTag {
Success = 0,
Blank = 1,
@ -627,7 +628,7 @@ pub mod simple_frontend {
#[wasm_bindgen]
pub struct WASMInitResult {
msg: String,
tag: WASMResultTag,
pub tag: WASMResultTag,
state: REPLState,
}
@ -641,10 +642,22 @@ pub mod simple_frontend {
}
}
#[wasm_bindgen]
impl WASMInitResult {
#[wasm_bindgen(getter)]
pub fn msg(&self) -> String {
self.msg.clone()
}
pub fn repl(self) -> REPLState {
self.state
}
}
#[wasm_bindgen]
pub struct WASMInputResult {
msg: String,
tag: WASMResultTag,
pub tag: WASMResultTag,
}
impl WASMInputResult {
@ -656,6 +669,14 @@ pub mod simple_frontend {
}
}
#[wasm_bindgen]
impl WASMInputResult {
#[wasm_bindgen(getter)]
pub fn msg(&self) -> String {
self.msg.clone()
}
}
pub enum InputResult {
Success(String),
Blank,
@ -696,7 +717,7 @@ pub mod simple_frontend {
}
#[wasm_bindgen]
pub fn wasm_input(mut state: REPLState, line: &str) -> WASMInputResult {
pub fn wasm_input(&mut state: REPLState, line: &str) -> WASMInputResult {
input(&mut state.0, line)
.map(WASMInputResult::from)
.unwrap_or_else(WASMInputResult::mk_error)