Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Utility: Difference between revisions

From Kronopolis and the Flat Plane
No edit summary
nil check on "firstToUpper()"
 
Line 2: Line 2:


function p.firstToUpper(str)
function p.firstToUpper(str)
     return (str:gsub("^%l", string.upper))
     if str ~= nil then
        return (str:gsub("^%l", string.upper))
    end
end
end



Latest revision as of 16:20, 27 May 2025

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

local p = {}

function p.firstToUpper(str)
    if str ~= nil then
        return (str:gsub("^%l", string.upper))
    end
end

function p.formatLevel(lv)
    local str
    if lv == 0 then str = 'Cantrip' 
    elseif lv == 1 then str = '1st' 
    elseif lv == 2 then str = '2nd' 
    elseif lv == 3 then str = '3rd' 
    else str = lv .. 'th'
    end
    return str
end

function p.dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = '"'..k..'"' end
         s = s .. '['..k..'] = ' .. p.dump(v) .. ','
      end
      return s .. '} '
   else
      return tostring(o)
   end
end


return p