thank you.
With JSON no experience, but with help from
this page I've got it working. The joined string goes to the string variable.
Code: Select all
function meld (melding,prio)
if (not prio) then print ('<font color="purple">test: E R R O R geen prio meegegeven') end
if debug==1 then print ('<font color="purple">test: '..melding) end
if prio~=99 then
commandArray[index]={['SendNotification']='test#'..melding..'#'..prio}
index = index + 1
end
end
function split(str, pat)
local t = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
return t
end
commandArray = {}
l = { -- timeout for each device, in seconde.
'PIR_woonkamer', 172800, 1, -- 2 dagen
'PIR badkamer',172800, 2 -- 2 dagen
}
debug=1
meld ('starttest',99)
i=1
meld ('the original elements:',99)
meld ('**********************',99)
while l[i] do
meld (i..':'..l[i]..'/'..l[i+1]..'/'..l[i+2],99)
i = i + 3
end
s=table.concat(l, ";")
meld ('the joined string:',99)
meld ('**********************',99)
meld (s,99)
l=split (s,';')
i=1
meld ('the join+split elements:',99)
meld ('**********************',99)
while l[i] do
meld (i..':'..l[i]..'/'..l[i+1]..'/'..l[i+2],99)
i = i + 3
end
return commandArray
Result:
2017-07-25 00:07:23.806 LUA: test: starttest
2017-07-25 00:07:23.806 LUA: test: the original elements:
2017-07-25 00:07:23.807 LUA: test: **********************
2017-07-25 00:07:23.807 LUA: test: 1:PIR_woonkamer/172800/1
2017-07-25 00:07:23.807 LUA: test: 4:PIR badkamer/172800/2
2017-07-25 00:07:23.808 LUA: test: the joined string:
2017-07-25 00:07:23.808 LUA: test: **********************
2017-07-25 00:07:23.809 LUA: test: PIR_woonkamer;172800;1;PIR badkamer;172800;2
2017-07-25 00:07:23.810 LUA: test: the join+split elements:
2017-07-25 00:07:23.810 LUA: test: **********************
2017-07-25 00:07:23.810 LUA: test: 1:PIR_woonkamer/172800/1
2017-07-25 00:07:23.810 LUA: test: 4:PIR badkamer/172800/2