Module:Boolean converter

From Linguifex
Revision as of 21:00, 17 January 2019 by Учхљёная (talk | contribs) (Created page with "-- #invoke. It is intended for use by other Lua modules, and should not be -- called from #invoke directly. return function (val, default) val = type(val) == 'string' and va...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Boolean converter/doc

-- #invoke. It is intended for use by other Lua modules, and should not be
-- called from #invoke directly.

return function (val, default)
	val = type(val) == 'string' and val:lower() or val
	if val == nil then
		return nil
	elseif val == true 
		or val == 'yes'
		or val == 'y'
		or val == 'true'
		or val == 't'
		or val == 'on'
		or val == 'дьэ'
		or tonumber(val) == 1
	then
		return true
	elseif val == false
		or val == 'no'
		or val == 'n'
		or val == 'false'
		or val == 'f'
		or val == 'off'
		or val == 'њэд'
		or tonumber(val) == 0
	then
		return false
	else
		return default
	end
end