-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdo_string.rs
More file actions
25 lines (22 loc) · 813 Bytes
/
do_string.rs
File metadata and controls
25 lines (22 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use crate::convert_err;
use lua::State;
use neon::prelude::*;
pub fn do_string_sync(mut cx: FunctionContext) -> JsResult<JsValue> {
let program = cx.argument::<JsString>(0)?.value(&mut cx);
let mut state = State::new();
state.open_libs();
let status = state.do_string(&program);
convert_err(status, &mut state, &mut cx)
}
pub fn do_string_async(mut cx: FunctionContext) -> JsResult<JsValue> {
let program = cx.argument::<JsString>(0)?.value(&mut cx);
let promise = cx
.task(move || {
let mut state = State::new();
state.open_libs();
let status = state.do_string(&program);
(state, status)
})
.promise(|mut cx, (mut state, status)| convert_err(status, &mut state, &mut cx));
Ok(promise.as_value(&mut cx))
}