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

Module:Utilities: Difference between revisions

From Sekaipedia
Content added Content deleted
(maybe correct concat)
mNo edit summary
Line 33: Line 33:
-- https://stackoverflow.com/questions/49907620/how-to-fuse-array-in-lua/49908683
-- https://stackoverflow.com/questions/49907620/how-to-fuse-array-in-lua/49908683
function utilities.table_concat(a, b)
function utilities.table_concat(a, b)
local result = {table.unpack(a)}
local result = {unpack(a)}
table.move(b, 1, #b, #result + 1, result)
table.move(b, 1, #b, #result + 1, result)
return result
return result

Revision as of 06:10, 13 August 2021

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

local utilities = {}

-- https://stackoverflow.com/questions/1426954/split-string-in-lua
function utilities.split(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t = {}
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        table.insert(t, str)
    end
    return t
end

function utilities.trim(str)
	return string.gsub(str, "^%s*(.-)%s*$", "%1")
end

function utilities.capitalize(str)
	return str:sub(1, 1):upper() .. str:sub(2, -1)
end

function utilities.array_index_of(arr, val)
    for i,v in ipairs(arr) do
        if v == val then
            return i
        end
    end

    return -1
end

-- https://stackoverflow.com/questions/49907620/how-to-fuse-array-in-lua/49908683
function utilities.table_concat(a, b)
	local result = {unpack(a)}
	table.move(b, 1, #b, #result + 1, result)
	return result
end


return utilities
Cookies help us deliver our services. By using our services, you agree to our use of cookies.