fix: reuse init logic in Runner::init_with_db
This commit is contained in:
parent
99403b7282
commit
3dbfbe48ce
@ -1015,19 +1015,10 @@ impl Runner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_with_db(db: &mut DB) -> ScriptResult<Self> {
|
pub fn init_with_db(db: &mut DB) -> ScriptResult<Self> {
|
||||||
let context = Context::new(None)?;
|
let mut runner = Self::init()?;
|
||||||
let mut global = context.global()?;
|
runner.call_attacher(|c, o| attach_db_obj(c, o, db))??;
|
||||||
attach_db_obj(&context, &mut global, db)?;
|
|
||||||
|
|
||||||
context.add_callback("print", |a: String| {
|
Ok(runner)
|
||||||
print(a);
|
|
||||||
|
|
||||||
None::<bool>
|
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok(Runner {
|
|
||||||
context: Arc::new(Mutex::new(context)),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn call_attacher<F, R>(&mut self, f: F) -> ScriptResult<R>
|
pub fn call_attacher<F, R>(&mut self, f: F) -> ScriptResult<R>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user