diff --git a/scripts/frame_counter.rn b/scripts/frame_counter.rn index 95d9c1e..e80e504 100644 --- a/scripts/frame_counter.rn +++ b/scripts/frame_counter.rn @@ -9,6 +9,6 @@ impl FrameCounter { pub fn update(self) { self.frame += 1; - println(`Frame: ${self.frame}`); + log::info(`Frame: ${self.frame}`); } } diff --git a/src/api.rs b/src/api.rs new file mode 100644 index 0000000..653eddb --- /dev/null +++ b/src/api.rs @@ -0,0 +1,41 @@ +pub mod log { + use anyhow::Result; + use rune::Module; + + #[rune::module(::log)] + pub fn module() -> Result { + 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}"); + } +} diff --git a/src/main.rs b/src/main.rs index 2451fbe..0e35905 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +mod api; mod gfx; mod input; @@ -33,7 +34,9 @@ pub fn main() -> Result<()> { pub fn run(event_loop: EventLoop<()>, mut context: Context) -> Result<()> { // !HACK: Temporrary scripting engine setup 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 mut sources = Sources::new(); sources.insert(Source::from_path(format!("{source_dir}/frame_counter.rn"))?)?;