diff options
Diffstat (limited to 'script/vm/node.lua')
-rw-r--r-- | script/vm/node.lua | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua index 3145a34d..6ef7c9d5 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -146,43 +146,30 @@ function mt:getData(k) end function mt:addOptional() - if self:isOptional() then - return self - end self.optional = true end function mt:removeOptional() - if not self:isOptional() then - return self - end - self:_expand() - for i = #self, 1, -1 do - local n = self[i] - if n.type == 'nil' - or (n.type == 'boolean' and n[1] == false) - or (n.type == 'doc.type.boolean' and n[1] == false) then - self[i] = self[#self] - self[#self] = nil - end - end + self.optional = false end ---@return boolean function mt:isOptional() - if self.optional ~= nil then - return self.optional + return self.optional == true +end + +---@return boolean +function mt:isFalsy() + if self.optional then + return true end - self:_expand() for _, c in ipairs(self) do if c.type == 'nil' or (c.type == 'boolean' and c[1] == false) or (c.type == 'doc.type.boolean' and c[1] == false) then - self.optional = true return true end end - self.optional = false return false end @@ -196,6 +183,11 @@ function mt:eachObject() end end +---@return vm.node +function mt:copy() + return vm.createNode(self) +end + ---@param source parser.object | vm.generic ---@param node vm.node | vm.object ---@param cover? boolean |