mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-18 07:11:04 +02:00
feat: new cairo module
Resolves #105 Co-authored-by: A-Cloud-Ninja <5809177+A-Cloud-Ninja@users.noreply.github.com>
This commit is contained in:
parent
7b089495ad
commit
b0a05b7cda
13 changed files with 587 additions and 21 deletions
41
src/clients/lua.rs
Normal file
41
src/clients/lua.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use mlua::Lua;
|
||||
use std::ops::Deref;
|
||||
use std::path::Path;
|
||||
use tracing::{debug, error};
|
||||
|
||||
/// Wrapper around Lua instance
|
||||
/// to create a singleton and handle initialization.
|
||||
#[derive(Debug)]
|
||||
pub struct LuaEngine {
|
||||
lua: Lua,
|
||||
}
|
||||
|
||||
impl LuaEngine {
|
||||
pub fn new(config_dir: &Path) -> Self {
|
||||
let lua = unsafe { Lua::unsafe_new() };
|
||||
|
||||
let user_init = config_dir.join("init.lua");
|
||||
if user_init.exists() {
|
||||
debug!("loading user init script");
|
||||
|
||||
if let Err(err) = lua.load(user_init).exec() {
|
||||
error!("{err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
debug!("loading internal init script");
|
||||
if let Err(err) = lua.load(include_str!("../../lua/init.lua")).exec() {
|
||||
error!("{err:?}");
|
||||
}
|
||||
|
||||
Self { lua }
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for LuaEngine {
|
||||
type Target = Lua;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.lua
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue