From b60bfc7495506ead44ca77fd1c8fea942d5f04e7 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Fri, 1 Jun 2018 22:21:59 -0700 Subject: [PATCH] Make nil checks more robust. This represents an evolution in how I've been thinking about Lua -- using boolean coercion is generally a bad idea I think because it obscures the underlying types. It also makes it so that if a boolean is eronneously passed into a function, and it happens to be a 'false' value, it will be coerced into the nil case instead of being reported as an error, no matter how unintuitive the resulting error might be. --- plugin/src/Reconciler.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugin/src/Reconciler.lua b/plugin/src/Reconciler.lua index fd3ab6cf..8158ddd6 100644 --- a/plugin/src/Reconciler.lua +++ b/plugin/src/Reconciler.lua @@ -94,7 +94,7 @@ function Reconciler:_reconcileChildren(rbx, item) while true do local itemChild, rbxChild = findNextChildPair(item.Children, rbxChildren, visited) - if not itemChild then + if itemChild == nil then break end @@ -105,7 +105,7 @@ function Reconciler:_reconcileChildren(rbx, item) while true do local rbxChild, itemChild = findNextChildPair(rbxChildren, item.Children, visited) - if not rbxChild then + if rbxChild == nil then break end @@ -133,7 +133,7 @@ function Reconciler:_reify(item) reparent(self:_reify(child), rbx) end - if item.Route then + if item.Route ~= nil then self._routeMap:insert(item.Route, rbx) end @@ -153,8 +153,8 @@ end ]] function Reconciler:reconcile(rbx, item) -- Item was deleted - if not item then - if rbx then + if item == nil then + if rbx ~= nil then self._routeMap:removeByRbx(rbx) rbx:Destroy() end @@ -163,7 +163,7 @@ function Reconciler:reconcile(rbx, item) end -- Item was created! - if not rbx then + if rbx == nil then return self:_reify(item) end @@ -191,7 +191,7 @@ function Reconciler:reconcileRoute(route, item, itemRoute) local child = rbx:FindFirstChild(piece) -- We should get services instead of making folders here. - if rbx == game and not child then + if rbx == game and child == nil then local success success, child = pcall(game.GetService, game, piece)