From c6f64c34efc92130e808555a9319b6c51d85fc6a Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 29 May 2025 21:01:49 +0300 Subject: [PATCH] improve gui properties-related error messages --- src/logic/scripting/lua/libs/libgui.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/logic/scripting/lua/libs/libgui.cpp b/src/logic/scripting/lua/libs/libgui.cpp index af317f94..68327c8e 100644 --- a/src/logic/scripting/lua/libs/libgui.cpp +++ b/src/logic/scripting/lua/libs/libgui.cpp @@ -490,6 +490,12 @@ static int p_get_scroll(UINode* node, lua::State* L) { } static int l_gui_getattr(lua::State* L) { + if (!lua::isstring(L, 1)) { + throw std::runtime_error("document name is not a string"); + } + if (!lua::isstring(L, 2)) { + throw std::runtime_error("element id is not a string"); + } auto docname = lua::require_string(L, 1); auto element = lua::require_string(L, 2); if (lua::isnumber(L, 3)) { @@ -507,6 +513,9 @@ static int l_gui_getattr(lua::State* L) { const auto& id = request_node_id(DocumentNode {docnode.document, node}); return push_document_node(L, id); } + if (!lua::isstring(L, 3)) { + throw std::runtime_error("attribute name is not a string"); + } auto attr = lua::require_string(L, 3); static const std::unordered_map< @@ -755,6 +764,15 @@ static int p_set_scroll(UINode* node, lua::State* L, int idx) { } static int l_gui_setattr(lua::State* L) { + if (!lua::isstring(L, 1)) { + throw std::runtime_error("document name is not a string"); + } + if (!lua::isstring(L, 2)) { + throw std::runtime_error("element id is not a string"); + } + if (!lua::isstring(L, 3)) { + throw std::runtime_error("attribute name is not a string"); + } auto docname = lua::require_string(L, 1); auto element = lua::require_string(L, 2); auto attr = lua::require_string(L, 3);