diff options
author | alyx <alyx@aleteoryx.me> | 2024-04-04 20:41:12 -0400 |
---|---|---|
committer | alyx <alyx@aleteoryx.me> | 2024-04-04 20:41:12 -0400 |
commit | 21ffaa07a20ccec702a77278724c6f78351a96f2 (patch) | |
tree | 1f965538c6d5c5d7b7b98ed0fffe93c7081e2e94 /src/theming/lua.rs | |
parent | 4424fb9b44c893dc937dc5077be7ef819680ea2c (diff) | |
download | lfm_embed-21ffaa07a20ccec702a77278724c6f78351a96f2.tar.gz lfm_embed-21ffaa07a20ccec702a77278724c6f78351a96f2.tar.bz2 lfm_embed-21ffaa07a20ccec702a77278724c6f78351a96f2.zip |
Start of Lua support
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) +}); |