Modul:Funktioner

Från Nordens Stjärnors officiella handbok
Version från den 29 oktober 2023 kl. 20.22 av Svenska Superserier (diskussion | bidrag) (Skapade sidan med 'local p = {} function p.explode( sep, text ) local sep, fields = sep or "::", {} local pattern = string.format("([^%s]+)", sep) text:gsub(pattern, function(c) fields[#fields+1] = c end) return fields end function p.trim(s) if type(s) == "string" then return (s:gsub("^%s*(.-)%s*$", "%1")) else return false end end function p.isempty(s) local result = false if type(s) == "nil" then result = true elseif type(s) == "string" then if s == "" then result...')
(skillnad) ← Äldre version | Nuvarande version (skillnad) | Nyare version → (skillnad)

Dokumentationen för denna modul kan skapas på Modul:Funktioner/dok

Skriptfel: Luafel: Internt fel: Tolken har avslutats med signalen "11".

local p = {}

function p.explode( sep, text )
	local sep, fields = sep or "::", {}
	local pattern = string.format("([^%s]+)", sep)
	text:gsub(pattern, function(c) fields[#fields+1] = c end)
	return fields
end

function p.trim(s)
	if type(s) == "string" then
		return (s:gsub("^%s*(.-)%s*$", "%1"))
	else
		return false
	end
end

function p.isempty(s)
	local result = false
	if type(s) == "nil" then
		result = true
	elseif type(s) == "string" then
		if s == "" then
			result = true
		end
	elseif type(s) == "table" then
		if next(s) == nil then
			result = true
		end
	end
	return result
end