Page 1 of 1
[SOLVED] debug commandArray
Posted: Tuesday 26 April 2016 21:32
by jmleglise
Hi,
Does anybody know how to print the content of commandArray ?
In a very big LUA script, I prepare a lot of command in commandArray like this :
Code: Select all
commandArray[1]={['device']='Off'}
commandArray[2]={['device'']='Stopped AFTER 5'}
commandArray[3]={['device']='Off AFTER 300'}
commandArray[4]={['deviceX']='Off'}
...
return commandArray
But I have a bug, and I would like to check what I finally have in commandArray
Re: debug commandArray
Posted: Tuesday 26 April 2016 21:44
by jvdz
This should work at the end of the script:
Code: Select all
for i, v in pairs(commandArray) do
print('### ++++++> Device Changes in commandArray: '..i..':'..v)
end
return commandArray
EDIT:this works for the shown format:
Code: Select all
commandArray = {}
commandArray[1]={['device']='Off'}
commandArray[2]={['device']='Stopped AFTER 5'}
commandArray[3]={['device']='Off AFTER 300'}
commandArray[4]={['device']='Off'}
for i, v in pairs(commandArray) do
print('### ++++++> Device Changes in commandArray: '..i..':' .. v["device"])
end
Jos
Re: debug commandArray
Posted: Tuesday 26 April 2016 22:37
by jmleglise
Thank you. You put me on the right way !
As my commandArray is filled with different device like this :
commandArray[1]={['motion']='On'}
commandArray[2]={['temp']='Off'}
commandArray[3]={['door']='On'}
the complete solution is :
Code: Select all
for i, v in pairs(commandArray) do
for namedevice, t in pairs(v) do
print('### ++++++> Device Changes in commandArray: '..i..namedevice.. v[namedevice])
end
end
I did not understand everything. But that works !

Re: debug commandArray
Posted: Wednesday 27 April 2016 10:14
by jvdz
Just to make this work for both formats of responses in commmandArray:
Code: Select all
commandArray["test"]='Off'
commandArray["test3"]='Off AFTER 300'
commandArray[1]={['tdevice']='Off'}
commandArray[2]={['adevice']='Stopped AFTER 5'}
commandArray[3]={['cdevice']='Off AFTER 300'}
commandArray[4]={['bdevice']='Off'}
print('### ++++++> Device Changes in commandArray: ')
for i, v in pairs(commandArray) do
if type(v) == "table" then
for namedevice, t in pairs(v) do
print('### '..i.."="..namedevice.."->".. v[namedevice])
end
else
print('### '..i.."->".. v)
end
end
Jos
