// 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)
});