diff options
Diffstat (limited to 'src/theming/lua.rs')
-rw-r--r-- | src/theming/lua.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/theming/lua.rs b/src/theming/lua.rs new file mode 100644 index 0000000..22ad4d6 --- /dev/null +++ b/src/theming/lua.rs @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: AGPL-3.0-only +use std::sync::LazyLock; +use std::collections::BTreeMap; +use std::ops::Deref; + +use tokio::sync::Mutex; +use mlua::*; + +use crate::CONFIG; + +static LUA: LazyLock<Mutex<Lua>> = LazyLock::new(|| { + let stdlib = StdLib::TABLE | StdLib::STRING | StdLib::UTF8 | StdLib::BIT | StdLib::MATH; + let lua = Lua::new_with(stdlib, LuaOptions::new().thread_pool_size(2)).expect("lua initialization"); + + lua.sandbox(true).expect("lua initialization"); + + lua.set_compiler( + if CONFIG.theme_debug { Compiler::new().set_optimization_level(0).set_debug_level(2) } + else { Compiler::new().set_optimization_level(2).set_debug_level(1) } + ); + + let expect: Value = lua.load(include_str!("lua-lib/expect.lua")) + .set_compiler(Compiler::new().set_optimization_level(2).set_debug_level(1)) + .eval() + .expect("expect.lua loading"); + lua.globals().set("expect", expect); + + let html: Value = lua.load(include_str!("lua-lib/html.lua")) + .set_compiler(Compiler::new().set_optimization_level(2).set_debug_level(1)) + .eval() + .expect("html.lua loading"); + lua.globals().set("html", html); + + Mutex::new(lua) +}); |