Register logging module and use in existing script
This commit is contained in:
parent
6abe5b467e
commit
58064c4fc1
|
@ -9,6 +9,6 @@ impl FrameCounter {
|
||||||
|
|
||||||
pub fn update(self) {
|
pub fn update(self) {
|
||||||
self.frame += 1;
|
self.frame += 1;
|
||||||
println(`Frame: ${self.frame}`);
|
log::info(`Frame: ${self.frame}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
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,3 +1,4 @@
|
||||||
|
mod api;
|
||||||
mod gfx;
|
mod gfx;
|
||||||
mod input;
|
mod input;
|
||||||
|
|
||||||
|
@ -33,7 +34,9 @@ pub fn main() -> Result<()> {
|
||||||
pub fn run(event_loop: EventLoop<()>, mut context: Context) -> Result<()> {
|
pub fn run(event_loop: EventLoop<()>, mut context: Context) -> Result<()> {
|
||||||
// !HACK: Temporrary scripting engine setup
|
// !HACK: Temporrary scripting engine setup
|
||||||
let source_dir = format!("{}/scripts", env!("CARGO_MANIFEST_DIR"));
|
let source_dir = format!("{}/scripts", env!("CARGO_MANIFEST_DIR"));
|
||||||
let rune_context = rune::Context::with_default_modules()?;
|
let mut rune_context = rune::Context::with_default_modules()?;
|
||||||
|
rune_context.install(api::log::module()?)?;
|
||||||
|
|
||||||
let runtime = Arc::new(rune_context.runtime()?);
|
let runtime = Arc::new(rune_context.runtime()?);
|
||||||
let mut sources = Sources::new();
|
let mut sources = Sources::new();
|
||||||
sources.insert(Source::from_path(format!("{source_dir}/frame_counter.rn"))?)?;
|
sources.insert(Source::from_path(format!("{source_dir}/frame_counter.rn"))?)?;
|
||||||
|
|
Loading…
Reference in New Issue