Logic Machine Forum
Custom values (enums) - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Custom values (enums) (/showthread.php?tid=2297)



Custom values (enums) - Thomas - 22.10.2019

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


RE: Custom values (enums) - admin - 22.10.2019

enums are encoded using JSON so you need to use json.decode


RE: Custom values (enums) - Thomas - 22.10.2019

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