Fixed xml scope access
This commit is contained in:
@@ -169,5 +169,4 @@ function BaseFrame:render()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return BaseFrame
|
return BaseFrame
|
||||||
@@ -74,19 +74,43 @@ local XMLParser = {
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
local log = require("log").debug
|
local function findExpressions(text)
|
||||||
|
local expressions = {}
|
||||||
|
local lastIndex = 1
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local startPos, endPos, expr = text:find("%${([^}]+)}", lastIndex)
|
||||||
|
if not startPos then break end
|
||||||
|
|
||||||
|
table.insert(expressions, {
|
||||||
|
start = startPos,
|
||||||
|
ending = endPos,
|
||||||
|
expression = expr,
|
||||||
|
raw = text:sub(startPos, endPos)
|
||||||
|
})
|
||||||
|
|
||||||
|
lastIndex = endPos + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return expressions
|
||||||
|
end
|
||||||
|
|
||||||
local function convertValue(value, scope)
|
local function convertValue(value, scope)
|
||||||
if value:sub(1,1) == "\"" and value:sub(-1) == "\"" then
|
if value:sub(1,1) == "\"" and value:sub(-1) == "\"" then
|
||||||
value = value:sub(2, -2)
|
value = value:sub(2, -2)
|
||||||
end
|
end
|
||||||
|
|
||||||
if value:sub(1,2) == "${" and value:sub(-1) == "}" then
|
local expressions = findExpressions(value)
|
||||||
value = value:sub(3, -2)
|
|
||||||
if(scope[value])then
|
for _, expr in ipairs(expressions) do
|
||||||
return scope[value]
|
local expression = expr.expression
|
||||||
|
local startPos = expr.start - 1
|
||||||
|
local endPos = expr.ending + 1
|
||||||
|
|
||||||
|
if scope[expression] then
|
||||||
|
value = value:sub(1, startPos) .. tostring(scope[expression]) .. value:sub(endPos)
|
||||||
else
|
else
|
||||||
errorManager.error("XMLParser: variable '" .. value .. "' not found in scope")
|
errorManager.error("XMLParser: variable '" .. expression .. "' not found in scope")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -154,9 +178,12 @@ function BaseElement:fromXML(node, scope)
|
|||||||
if(k:sub(1,2)=="on")then
|
if(k:sub(1,2)=="on")then
|
||||||
local val = v:gsub("\"", "")
|
local val = v:gsub("\"", "")
|
||||||
if(scope[val])then
|
if(scope[val])then
|
||||||
|
if(type(scope[val]) ~= "function")then
|
||||||
|
errorManager.error("XMLParser: variable '" .. val .. "' is not a function for element '" .. self:getType() .. "' "..k)
|
||||||
|
end
|
||||||
self[k](self, scope[val])
|
self[k](self, scope[val])
|
||||||
else
|
else
|
||||||
errorManager.error("XMLParser: variable '" .. v .. "' not found in scope")
|
errorManager.error("XMLParser: variable '" .. val .. "' not found in scope")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
errorManager.error("XMLParser: property '" .. k .. "' not found in element '" .. self:getType() .. "'")
|
errorManager.error("XMLParser: property '" .. k .. "' not found in element '" .. self:getType() .. "'")
|
||||||
|
|||||||
Reference in New Issue
Block a user