lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>>        local t = split(s, "e")
>>        local m, e = t[1], t[2]
>>        local t = split(m, ".")
>
> What is the definition of split() ?

Sorry, I forgot about that one:

function split(s, sep)
	if not sep then sep = " " end
	local out = {}
	local start, stop = string.find(s, sep, 1, true)
	if start then
		out[#out + 1] = string.sub(s, 1, start - 1)
		return table_concat(out, split(string.sub(s, stop + 1), sep))
	else
		return {s}
	end
end
function dup(a)
	if type(a) ~= "table" then
		return a
	else
		local out = {}
		for i, j in pairs(a) do
			out[i] = dup(j)
		end
		return out
	end
end
function table_concat(t1, t2)
	if not t1 and not t2 then return {} end
	if not t1 then return t2 end
	if not t2 then return t1 end
	local t = dup(t1)
	for _, e in pairs(dup(t2)) do t[#t + 1] = e end
	return t
end



> An optimization tip would be to make local aliases for things like
> string.sub, etc
>
> steve d.
>
>