Refactor rune modules
This commit is contained in:
parent
6f8c99ed4c
commit
3cb044cde2
|
@ -1,41 +0,0 @@
|
|||
pub mod log {
|
||||
use anyhow::Result;
|
||||
use rune::Module;
|
||||
|
||||
#[rune::module(::log)]
|
||||
pub fn module() -> Result<Module> {
|
||||
let mut module = Module::from_meta(self::module_meta)?.with_unique("log");
|
||||
module.function_meta(info)?;
|
||||
module.function_meta(warn)?;
|
||||
module.function_meta(error)?;
|
||||
module.function_meta(trace)?;
|
||||
module.function_meta(debug)?;
|
||||
|
||||
Ok(module)
|
||||
}
|
||||
|
||||
#[rune::function]
|
||||
pub fn info(message: &str) {
|
||||
log::info!("{message}");
|
||||
}
|
||||
|
||||
#[rune::function]
|
||||
pub fn warn(message: &str) {
|
||||
log::warn!("{message}");
|
||||
}
|
||||
|
||||
#[rune::function]
|
||||
pub fn error(message: &str) {
|
||||
log::error!("{message}");
|
||||
}
|
||||
|
||||
#[rune::function]
|
||||
pub fn trace(message: &str) {
|
||||
log::trace!("{message}");
|
||||
}
|
||||
|
||||
#[rune::function]
|
||||
pub fn debug(message: &str) {
|
||||
log::debug!("{message}");
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
pub mod api;
|
||||
pub mod modules;
|
||||
mod runtime;
|
||||
|
||||
pub use runtime::Runtime;
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
use anyhow::Result;
|
||||
use rune::Module;
|
||||
|
||||
#[rune::module(::log)]
|
||||
pub fn module() -> Result<Module> {
|
||||
let mut module = Module::from_meta(self::module_meta)?.with_unique("log");
|
||||
module.function_meta(info)?;
|
||||
module.function_meta(warn)?;
|
||||
module.function_meta(error)?;
|
||||
module.function_meta(trace)?;
|
||||
module.function_meta(debug)?;
|
||||
|
||||
Ok(module)
|
||||
}
|
||||
|
||||
#[rune::function]
|
||||
pub fn info(message: &str) {
|
||||
log::info!("{message}");
|
||||
}
|
||||
|
||||
#[rune::function]
|
||||
pub fn warn(message: &str) {
|
||||
log::warn!("{message}");
|
||||
}
|
||||
|
||||
#[rune::function]
|
||||
pub fn error(message: &str) {
|
||||
log::error!("{message}");
|
||||
}
|
||||
|
||||
#[rune::function]
|
||||
pub fn trace(message: &str) {
|
||||
log::trace!("{message}");
|
||||
}
|
||||
|
||||
#[rune::function]
|
||||
pub fn debug(message: &str) {
|
||||
log::debug!("{message}");
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
pub mod log;
|
|
@ -7,7 +7,7 @@ use rune::{
|
|||
};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use super::api;
|
||||
use super::modules;
|
||||
|
||||
pub struct Runtime {
|
||||
pub vm: Vm,
|
||||
|
@ -17,7 +17,7 @@ pub struct Runtime {
|
|||
impl Runtime {
|
||||
pub fn new(source_dir: &str) -> Result<Self> {
|
||||
let mut context = Context::with_default_modules()?;
|
||||
context.install(api::log::module()?)?;
|
||||
context.install(modules::log::module()?)?;
|
||||
|
||||
let runtime = Arc::new(context.runtime()?);
|
||||
let mut diagnostics = Diagnostics::new();
|
||||
|
|
Loading…
Reference in New Issue