This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Custom values (enums)
#1
Hello
How to get safely custom values into a Lua table?
In Object.enums I see:
{"0":"OK","1":"On"..."255":"Error"}

I need a table containing:
t[0]="OK"
t[1]="On"
...
t[255]="Error"

Do you have a tested script which parse object.enums string into such table?

Thank you
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#2
enums are encoded using JSON so you need to use json.decode
Reply
#3
Tank you.
The whole solution is:

Code:
myobject = grp.find("24/3/16")
if (myobject.enums) then
  json = require('json')
  data = json.decode(myobject.enums)
  log(data[tostring(myobject.value)])
end
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply


Forum Jump: