From 98b4191504e681fd42f4ac2644e76644d8f9a7e9 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Wed, 12 Feb 2025 08:49:37 +0100 Subject: [PATCH] small fixxes for xml Small fixxes for xml usage --- Basalt/main.lua | 2 +- Basalt/objects/Container.lua | 2 +- Basalt/plugins/reactive.lua | 21 ++++++++++++++++----- Basalt/plugins/themes.lua | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Basalt/main.lua b/Basalt/main.lua index 206700c..dd378d6 100644 --- a/Basalt/main.lua +++ b/Basalt/main.lua @@ -78,7 +78,7 @@ local getObject = function(objectName) return getObjects()[objectName] end -local createObject = function(basalt, objectName, id) +local createObject = function(objectName, id) return getObject(objectName)(id, basalt) end diff --git a/Basalt/objects/Container.lua b/Basalt/objects/Container.lua index 1b73d16..ba54f24 100644 --- a/Basalt/objects/Container.lua +++ b/Basalt/objects/Container.lua @@ -419,7 +419,7 @@ return function(name, basalt) for objectName, _ in pairs(basalt.getObjects()) do container["add" .. objectName] = function(self, id) - return self:addChild(basalt:createObject(objectName, id)) + return self:addChild(basalt.createObject(objectName, id)) end end diff --git a/Basalt/plugins/reactive.lua b/Basalt/plugins/reactive.lua index 85f58fb..28274ee 100644 --- a/Basalt/plugins/reactive.lua +++ b/Basalt/plugins/reactive.lua @@ -100,7 +100,7 @@ end return { basalt = function(basalt) - local createObjectsFromXMLNode = function(node, env) + local function createObjectsFromXMLNode(node, env) local layout = env[node.tag] if (layout ~= nil) then local props = {} @@ -109,12 +109,20 @@ return { end return basalt.createObjectsFromLayout(layout, props) end - local objectName = node.tag:gsub("^%l", string.upper) - local object = basalt:createObject(objectName, node.attributes["id"]) + local object = basalt.createObject(objectName, node.attributes["id"]) for attribute, expression in pairs(node.attributes) do if (attribute:sub(1, 2) == "on") then - registerFunctionEvent(object, object[attribute], expression .. "()", env) + object[attribute](object, function(...) + local basaltCallback = basalt.getVariable(expression:gsub("\"", ""):gsub("\'", "")) + if(basaltCallback ~= nil) then + basaltCallback() + elseif(env[expression] ~= nil) then + env[expression]() + else + registerFunctionEvent(object, object[attribute], expression .. "()", env) + end + end) else local update = function() local value = load("return " .. expression, nil, "t", env)() @@ -124,7 +132,7 @@ return { end end for _, child in ipairs(node.children) do - local childObjects = basalt.createObjectsFromXMLNode(child, env) + local childObjects = createObjectsFromXMLNode(child, env) for _, childObject in ipairs(childObjects) do object:addChild(childObject) end @@ -159,6 +167,9 @@ return { end setmetatable(env.props, { __index = function(_, k) + if(updateFns[k] == nil) then + error("Property " .. k .. " not found") + end return updateFns[k]() end }) diff --git a/Basalt/plugins/themes.lua b/Basalt/plugins/themes.lua index 414e11b..5442d21 100644 --- a/Basalt/plugins/themes.lua +++ b/Basalt/plugins/themes.lua @@ -88,7 +88,7 @@ plugin[v] = function(base, name, basalt) if(base.init(self))then local parent = self:getParent() or self self:setBackground(parent:getTheme(v.."BG")) - self:setForeground(parent:getTheme(v.."Text")) + self:setForeground(parent:getTheme(v.."Text")) end end }