Expand Lua libraries and enhance error recovery logic.

Added more Lua libraries to extend scripting capabilities within the application. Improved error handling by re-enabling the UI button and reloading the webview after a Lua script failure.
This commit is contained in:
2024-12-16 08:29:58 +01:00
parent 6cd4b0a608
commit 5b61db140e

View File

@@ -246,7 +246,17 @@ void ToolboxWindow::run_lua(int id) {
// Lambda-Funktion, um das Lua-Skript auszuführen
auto lua_task = [this, id]() {
sol::state lua;
lua.open_libraries(sol::lib::base, sol::lib::os);
lua.open_libraries(sol::lib::base,
sol::lib::os,
sol::lib::string,
sol::lib::string,
sol::lib::coroutine,
sol::lib::package,
sol::lib::table,
sol::lib::math,
sol::lib::utf8,
sol::lib::coroutine,
sol::lib::io);
try {
std::string scriptPath = m_toolboxItems[id].lua_script;
@@ -255,6 +265,8 @@ void ToolboxWindow::run_lua(int id) {
m_webview.reload();
} catch (const sol::error& e) {
std::cerr << "Lua error: " << e.what() << std::endl;
m_webview.execute("enableButtonByToolId({})",saucer::make_args(id));
m_webview.reload();
}
};