In order to edit this wiki, you must register and verify your account.

Module:Paramtest: Difference between revisions

From Cemu Wiki
Jump to:navigation Jump to:search
(Created page with "-- -- Tests basic properties of parameters. -- local p = {} -- -- Tests if the parameter is empty, all white space, or undefined. -- function p.is_empty(arg) return not st...")
(No difference)

Revision as of 20:45, 31 October 2021

-- -- Tests basic properties of parameters. --

local p = {}

-- -- Tests if the parameter is empty, all white space, or undefined. --

function p.is_empty(arg) return not string.find(arg or , '%S') end

-- -- Returns the parameter if it has any content. --

function p.default_to(arg, default) if string.find(arg or , '%S') then return arg else return default end end

-- -- Returns a list of parameters if they have any content. -- function p.defaults(...) local ret = {} for i, v in ipairs(...) do if string.find(v[1] or , '%S') then table.insert(ret,v[1]) else -- or false, because nil is removed table.insert(ret,v[2] or false) end end return unpack(ret) end

-- -- Tests if the parameter has content. --

function p.has_content(arg) return string.find(arg or , '%S') end

-- -- Uppercase the first letter. --

function p.ucfirst(arg) if not arg or arg:len() == 0 then return nil elseif arg:len() == 1 then return arg:upper() else return arg:sub(1,1):upper() .. arg:sub(2) end end

-- -- Uppercase the first letter, lowercase everything else. --

function p.ucflc(arg) if not arg or arg:len() == 0 then return nil elseif arg:len() == 1 then return arg:upper() else return arg:sub(1,1):upper() .. arg:sub(2):lower() end end

return p