oUF

97.2k Downloads

AddElement arguments requirement inconsistencies.

gizzmo opened this issue ยท 2 comments

commented

The AddElement method says that the Update, Enable, and Disable functions are optional. But according to the code, they're not. I assume they're not meant to be, and it's just an incorrect docs issue.

oUF/ouf.lua

Lines 852 to 860 in abdc99e

* update - used to update the element (function?)
* enable - used to enable the element for a given unit frame and unit (function?)
* disable - used to disable the element for a given unit frame (function?)
--]]
function oUF:AddElement(name, update, enable, disable)
argcheck(name, 2, 'string')
argcheck(update, 3, 'function', 'nil')
argcheck(enable, 4, 'function', 'nil')
argcheck(disable, 5, 'function', 'nil')

oUF/ouf.lua

Line 113 in abdc99e

if(element.enable(self, unit or self.unit)) then

oUF/ouf.lua

Line 144 in abdc99e

return elements[name].disable(self)

So Update can be optional

oUF/ouf.lua

Lines 116 to 118 in abdc99e

if(element.update) then
table.insert(self.__elements, element.update)
end

But it would make this loop pointless.

oUF/ouf.lua

Lines 134 to 140 in abdc99e

local update = elements[name].update
for k, func in next, self.__elements do
if(func == update) then
table.remove(self.__elements, k)
break
end
end

Bonus bug I just noticed. The arg number is wrong in those argcheck calls

commented

The documentation is not wrong, it's the code

oUF/ouf.lua

Lines 858 to 860 in abdc99e

argcheck(update, 3, 'function', 'nil')
argcheck(enable, 4, 'function', 'nil')
argcheck(disable, 5, 'function', 'nil')

It explicitly allows for nil. I'll take a look at it later just to make sure it does not break something and fix accordingly.

Bonus bug I just noticed. The arg number is wrong in those argcheck calls

Nope, self is the first argument.

thing:func(arg2, arg3) is syntactic sugar for thing.func(thing, arg2, arg3)

commented

Nope, self is the first argument.

Ah yeah, forgot about that.