Fix (#90)
This commit is contained in:
@@ -36,37 +36,6 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
basalt = function(basalt)
|
basalt = function(basalt)
|
||||||
local createObjectsFromXMLNode = function(node, env)
|
|
||||||
local layout = env[node.tag]
|
|
||||||
if (layout ~= nil) then
|
|
||||||
local props = {}
|
|
||||||
for prop, expression in pairs(node.attributes) do
|
|
||||||
props[prop] = load("return " .. expression, nil, "t", env)
|
|
||||||
end
|
|
||||||
return basalt.createObjectsFromLayout(layout, props)
|
|
||||||
end
|
|
||||||
|
|
||||||
local objectName = node.tag:gsub("^%l", string.upper)
|
|
||||||
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)
|
|
||||||
else
|
|
||||||
Reactive.effect(function()
|
|
||||||
local value = load("return " .. expression, nil, "t", env)()
|
|
||||||
object:setProperty(attribute, value)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for _, child in ipairs(node.children) do
|
|
||||||
local childObjects = basalt.createObjectsFromXMLNode(child, env)
|
|
||||||
for _, childObject in ipairs(childObjects) do
|
|
||||||
object:addChild(childObject)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return {object}
|
|
||||||
end
|
|
||||||
|
|
||||||
local object = {
|
local object = {
|
||||||
observable = Reactive.observable,
|
observable = Reactive.observable,
|
||||||
derived = Reactive.derived,
|
derived = Reactive.derived,
|
||||||
@@ -84,6 +53,37 @@ return {
|
|||||||
return Layout.fromXML(text)
|
return Layout.fromXML(text)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
createObjectsFromXMLNode = function(node, env)
|
||||||
|
local layout = env[node.tag]
|
||||||
|
if (layout ~= nil) then
|
||||||
|
local props = {}
|
||||||
|
for prop, expression in pairs(node.attributes) do
|
||||||
|
props[prop] = load("return " .. expression, nil, "t", env)
|
||||||
|
end
|
||||||
|
return basalt.createObjectsFromLayout(layout, props)
|
||||||
|
end
|
||||||
|
|
||||||
|
local objectName = node.tag:gsub("^%l", string.upper)
|
||||||
|
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)
|
||||||
|
else
|
||||||
|
Reactive.effect(function()
|
||||||
|
local value = load("return " .. expression, nil, "t", env)()
|
||||||
|
object:setProperty(attribute, value)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for _, child in ipairs(node.children) do
|
||||||
|
local childObjects = basalt.createObjectsFromXMLNode(child, env)
|
||||||
|
for _, childObject in ipairs(childObjects) do
|
||||||
|
object:addChild(childObject)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return {object}
|
||||||
|
end,
|
||||||
|
|
||||||
createObjectsFromLayout = function(layout, props)
|
createObjectsFromLayout = function(layout, props)
|
||||||
local env = _ENV
|
local env = _ENV
|
||||||
env.props = {}
|
env.props = {}
|
||||||
@@ -105,7 +105,7 @@ return {
|
|||||||
end
|
end
|
||||||
local objects = {}
|
local objects = {}
|
||||||
for _, node in ipairs(layout.nodes) do
|
for _, node in ipairs(layout.nodes) do
|
||||||
local _objects = createObjectsFromXMLNode(node, env)
|
local _objects = basalt.createObjectsFromXMLNode(node, env)
|
||||||
for _, object in ipairs(_objects) do
|
for _, object in ipairs(_objects) do
|
||||||
table.insert(objects, object)
|
table.insert(objects, object)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user