Hello my program compiles but does not work
in fact I would like to be able to make a table from panel including tables
import json
var jsonTest = %* {
"titleTerm": "DESIGNER",
"panel": [] }
add(jsonTest["panel"], %* {
"name": "TEST",
"posx": 1,
"posy": 1,
"height": 42,
"width": 132,
"cadre": line1,
"title": "TEST-Panel",
"button" :[], "label":[],"field":[]})
add(jsonTest["panel"]["button"] , %* {"Tkey": "F3","txtKey": "Exit","actif": true})
add(jsonTest["panel"]["button"] , %* {"Tkey":"F9","txtKey": "Add","actif": true })
add(jsonTest["panel"]["button"] , %* {"Tkey": "F10","txtKey": "Update","actif": true})
add(jsonTest["panel"]["button"] , %* {"Tkey": "F12","txtKey": "Return","actif": true })
echo jsonTest
quit()
This works, but I lose panel in table
import json
var jsonPanel = %* {
"titleTerm": "DESIGNER",
"panel": {
"name": "TEST",
"posx": 1,
"posy": 1,
"height": 42,
"width": 132,
"cadre": line1,
"title": "TEST-Panel",
"button" :[], "label":[],"field":[]}
}
add(jsonPanel["panel"]["button"] , %* {"Tkey": "F3","txtKey": "Exit","actif": true})
add(jsonPanel["panel"]["button"] , %* {"Tkey": "F9","txtKey": "Add","actif": true })
add(jsonPanel["panel"]["button"] , %* {"Tkey": "F10","txtKey": "Update","actif": true})
add(jsonPanel["panel"]["button"] , %* {"Tkey":"F12","txtKey": "Return","actif": true })
# test format Json
echo jsonPanel
for n in 0..len(jsonPanel["panel"]["button"])-1:
echo jsonPanel["panel"]["button"][n]["Tkey"].getStr()
quit()
in fact by exposing you my problem I found, the panel index was missing ex:
add(jsonTest["panel"]|index]["button"]
Or you can drop std/json entirely and use the superior solution jsony
Yep, it's the typical case of either assuming every identifier given as a key is actually a string and disallowing variables as keys.
Or alternatively requiring a way to quote variables from the local scope (or possibly any expression returning a string).
Or as a final alternative doing the hacky thing that's kind of fun, but not advised for serious code: abuse declaredInScope for a CT check if something is a local variable or not.
How would you distinguish between variables and literals?
I think variable-key used rarely and could be ignored. So keys could always threated as literals. In JavaScript, it's possible to distinguish between literal and variable as { [key]: "some" } but it's almost never used or needed. If you need to set variable key, just use var o = %{ a: 1 }; o[somevar] = 2