¿Es posible hacer un colapso de variables sin hacer funciones individuales?
Tengo un código que comienza como una pequeña cantidad de variables y crea más elementos usando esas variables iniciales.
function new( x, y, width, height )
local object = {}
--border
object.border = { x = x, y = y, width = width, height = height }
--body
object.body = { x = x+1, y = y+1, width = width-2, height = height-2 }
--font
object.font = {}
object.font.size = (object.body.height+2)-(math.floor((object.body.height+2)/4)+1)
object.font.height = love.graphics.setNewFont( object.font.size ):getHeight()
--padding
object.padding = {}
object.padding.height = math.floor(object.border.height*(2/29))
object.padding.width = object.padding.height*3
--text
object.text = { input = '' }
object.text.centerHeight = math.ceil(object.body.y+((object.body.height-object.font.height)/2))
object.text.left = object.body.x+object.padding.width+object.padding.height
--backspacing
object.backspace = {key = false, rate = 3, time = 0, pausetime = 20, pause = true}
--config
object.config = { active = true, devmode = false, debug = false, id = gui.id(), type = 'textbox' }
gui.add(object)
return object.config.id
end
y cuando modifico algo en la parte media, todo se vuelve un desastre porque desde el que cambié hasta que los valores inferiores no coinciden entre sí
local x = gui.get(2)
x.body.height = 50
Estoy buscando si hay una manera de redefinir estas variables, comenzando desde ellas hasta el final, sin: (a) hacer funciones para cada una de las variables. y (b) editar los parámetros requeridos en la función.
y si no hay ninguno, ¿es la forma alternativa de hacer esto de manera eficiente?
EDITAR: la estructura de las variables es la siguiente:
border->body->padding->font
lo que necesitaba es una forma de definiralguna de ellos para que el que sigue también cambie como:
object.body.x = 15
y colapsaría desde esa variable redefinida hasta el final:
body->padding->font
podría redefinirlos desde la variable editada hasta la parte inferior de esta manera:
--not the actual code, just an example of variables dependent on the variable above
object.body.x = 15
object.padding.width = object.body.x+1
object.font.size = object.padding.width+1
pero eso significa que tengo que hacer lo mismo al redefinir el relleno hasta que la fuente sea extremadamente ineficiente, especialmente cuando extiendo más elementos.
ejemplo:
--padding->font
object.padding.width = 5
object.font.size = object.padding.width+1