small fixxes for xml
Small fixxes for xml usage
This commit is contained in:
@@ -78,7 +78,7 @@ local getObject = function(objectName)
|
|||||||
return getObjects()[objectName]
|
return getObjects()[objectName]
|
||||||
end
|
end
|
||||||
|
|
||||||
local createObject = function(basalt, objectName, id)
|
local createObject = function(objectName, id)
|
||||||
return getObject(objectName)(id, basalt)
|
return getObject(objectName)(id, basalt)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ return function(name, basalt)
|
|||||||
|
|
||||||
for objectName, _ in pairs(basalt.getObjects()) do
|
for objectName, _ in pairs(basalt.getObjects()) do
|
||||||
container["add" .. objectName] = function(self, id)
|
container["add" .. objectName] = function(self, id)
|
||||||
return self:addChild(basalt:createObject(objectName, id))
|
return self:addChild(basalt.createObject(objectName, id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
basalt = function(basalt)
|
basalt = function(basalt)
|
||||||
local createObjectsFromXMLNode = function(node, env)
|
local function createObjectsFromXMLNode(node, env)
|
||||||
local layout = env[node.tag]
|
local layout = env[node.tag]
|
||||||
if (layout ~= nil) then
|
if (layout ~= nil) then
|
||||||
local props = {}
|
local props = {}
|
||||||
@@ -109,12 +109,20 @@ return {
|
|||||||
end
|
end
|
||||||
return basalt.createObjectsFromLayout(layout, props)
|
return basalt.createObjectsFromLayout(layout, props)
|
||||||
end
|
end
|
||||||
|
|
||||||
local objectName = node.tag:gsub("^%l", string.upper)
|
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
|
for attribute, expression in pairs(node.attributes) do
|
||||||
if (attribute:sub(1, 2) == "on") then
|
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
|
else
|
||||||
local update = function()
|
local update = function()
|
||||||
local value = load("return " .. expression, nil, "t", env)()
|
local value = load("return " .. expression, nil, "t", env)()
|
||||||
@@ -124,7 +132,7 @@ return {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
for _, child in ipairs(node.children) do
|
for _, child in ipairs(node.children) do
|
||||||
local childObjects = basalt.createObjectsFromXMLNode(child, env)
|
local childObjects = createObjectsFromXMLNode(child, env)
|
||||||
for _, childObject in ipairs(childObjects) do
|
for _, childObject in ipairs(childObjects) do
|
||||||
object:addChild(childObject)
|
object:addChild(childObject)
|
||||||
end
|
end
|
||||||
@@ -159,6 +167,9 @@ return {
|
|||||||
end
|
end
|
||||||
setmetatable(env.props, {
|
setmetatable(env.props, {
|
||||||
__index = function(_, k)
|
__index = function(_, k)
|
||||||
|
if(updateFns[k] == nil) then
|
||||||
|
error("Property " .. k .. " not found")
|
||||||
|
end
|
||||||
return updateFns[k]()
|
return updateFns[k]()
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ plugin[v] = function(base, name, basalt)
|
|||||||
if(base.init(self))then
|
if(base.init(self))then
|
||||||
local parent = self:getParent() or self
|
local parent = self:getParent() or self
|
||||||
self:setBackground(parent:getTheme(v.."BG"))
|
self:setBackground(parent:getTheme(v.."BG"))
|
||||||
self:setForeground(parent:getTheme(v.."Text"))
|
self:setForeground(parent:getTheme(v.."Text"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user