Modul:SortingComparators

Dokumentaci tohoto modulu lze vytvořit na stránce Nápověda:Modul:SortingComparators

-- @brief
--  Various comparators for table.sort().
-- 
-- @author
--  [[meta:User:Danny B.]]
local _module = {}
----------------------------------------


-- @brief
--  Mixed scalar types sorting comparator.
-- 
-- @details
--  Accepts nil, boolean, number and string.
-- 
-- @param
--  mixed left First value
--  mixed right Second value
-- 
-- @return
--  boolean true if type( left ) < type( right ) or left < right
--  boolean false otherwise
function _module.mixedScalarTypes( left, right )
	
	assert(
		type( left ) == "nil"
			or type( left ) == "boolean"
			or type( left ) == "number"
			or type( left ) == "string",
		string.format( "Unallowed type: %s", type( left ) )
	)
	assert(
		type( right ) == "nil"
			or type( right ) == "boolean"
			or type( right ) == "number"
			or type( right ) == "string",
		string.format( "Unallowed type: %s", type( right ) )
	)
	
	if type( left ) == type( right ) then
		return left < right
	else
		return type( left ) < type( right )
	end
	
end


----------------------------------------
return _module