Module:RemiLib

Revision as of 16:28, 4 May 2015 by Remi Scarlet (talk | contribs) (Created page with "local p = {} -- Module for random library functions for lua because lua sucks. Written by -- Remi_Scarlet -- I fucking hate lua. -- takes a string and returns string with f...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note

These are literally just random library functions that I use often. Please try to avoid touching it if possible (or at least contact me if you really want to change something).

You're obviously free to use these for your own modules if you so wish.


local p = {}

-- Module for random library functions for lua because lua sucks. Written by
-- Remi_Scarlet
-- I fucking hate lua.


-- takes a string and returns string with first letter capitalized
function p.capitalize(str)
    return (str:gsub("^%l", string.upper))
end

-- returns a string representation of a table.
-- cannot do recursive tables. Eg, only single dimensional tables will work
-- should a multi-dimensional table be given, it will simply put "table" as the value
function p.dictConcat(dict,sep)
    if sep == nil then sep = " | " end
    local final = ""
    for k,v in pairs(dict) do
        if k ~= nil then
            if v ~= nil then
                final = final .. k .. "=" .. tostring(v) .. sep
            else
                final = final .. k .. "= nil" .. sep
            end
        else
            if v ~= nil then
                final = final .. tostring(v) .. sep 
            else
                final = final .. "nil" .. sep
            end
        end
    end
    return final
end


-- checks if data is in the array as a key
function p.valid(data, array)
    local valid = {}
    if array ~= nil then
        for i = 1, #array do
            valid[array[i]] = true
        end
        if valid[data] then
            return true
        else
            return false
        end
    end
end

return p