getStorageSafe
Definition
-- @/lua/vehicle/energyStorage.lua:218
local function getStorageSafe(name)
local storage = energyStorages[name]
if storage then
return storage
else
log("D", "energyStorage.getStorageSafe", string.format("Didn't find storage '%s', returning nilStorage.", name))
--log("D", "energyStorage.getStorageSafe", debug.traceback())
--return our nilStorage that accepts all indexes and can be called without errors
return M.nilStorage
end
end
Callers
@/lua/vehicle/energyStorage.lua
--in this case an error is thrown if "abc" is not a valid storage.
--Using energyStorage.getStorageSafe() instead returns a magic table that
--happily accepts all indexes and can be called without throwing errors (if no real storage is found)