lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Here comes a couple related questions:

1. when defining an API for a enable/disable type call, is nil supposed to be accepted as false, or not? In other words, is better to force to provide true/false, or just anything and then evaluate it to true or false?
This is:

----------------------
function M.feature_enable(p)
	if p then
		--enable
	else
		--disable
	end

end
----------------------

or

----------------------
function M.feature_enable(p)
	if p==true then
		--enable
	elseif p==false then
		--disable
	end
end
----------------------


2. What is the opinion on a API call defined as follows:
	* If a parameter is provided, it is applied
	* If no parameter or nil is provided, nothing is changed
        * The current value (as set or kept) are returned.

So, a "setter" would be M.feature_enable(true), and a "getter" would be M.feature_enable()



Jorge