Module:Utility: Difference between revisions

From Kronopolis and the Flat Plane
Created page with "function firstToUpper(str) return (str:gsub("^%l", string.upper)) end function 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"
 
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
function firstToUpper(str)
local p = {}
 
function p.firstToUpper(str)
     return (str:gsub("^%l", string.upper))
     return (str:gsub("^%l", string.upper))
end
end


function formatLevel(lv)
function p.formatLevel(lv)
     local str
     local str
     if lv == 0 then str = 'Cantrip'  
     if lv == 0 then str = 'Cantrip'  
Line 13: Line 15:
     return str
     return str
end
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

Latest revision as of 14:06, 3 March 2023

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

local p = {}

function p.firstToUpper(str)
    return (str:gsub("^%l", string.upper))
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