summaryrefslogtreecommitdiffstats
path: root/lib/join.lua
blob: e3621defe96de7402e1325c7622ad2f2ec0f19eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
--[[
	module for joining an array to a string
]]--

module (..., package.seeall)


-- This code comes from http://lua-users.org/wiki/SplitJoin
--
-- Concat the contents of the parameter list,
-- -- separated by the string delimiter (just like in perl)
-- -- example: strjoin(", ", {"Anna", "Bob", "Charlie", "Dolores"})
return function (delimiter, list)
	local len = getn(list)
	if len == 0 then 
		return "" 
	end
	local string = list[1]
	for i = 2, len do 
		string = string .. delimiter .. list[i] 
	end
	return string
end