From 21ffaa07a20ccec702a77278724c6f78351a96f2 Mon Sep 17 00:00:00 2001 From: alyx Date: Thu, 4 Apr 2024 20:41:12 -0400 Subject: Start of Lua support --- src/theming/lua.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/theming/lua.rs (limited to 'src/theming/lua.rs') 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> = 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) +}); -- cgit v1.2.3-54-g00ecf