6.4 示例
6.4.1 将某个变量结果+1
function calc(current,last)
=current+1
currentreturn current
end
6.4.2 将某个变量结果 追加一个字符串
function calc(current,last)
=current .. "woody"
currentreturn current
end
6.4.3 联合两个变量计算出新的变量
function calc(value)
if(value.cnc_runstatus==1 and #value.cnc_alarm>0)
then
.custom=2
valueend
return value
end
6.4.4 删除某个变量
function calc(value)
.cnc_runstatus=nil
valuereturn value
end
6.4.5 将Alarm的Array[Object]展开成普通变量
{
"cnc_alarm": [
{
"alarm_no": 1,
"alarm_type": "T01",
"alarm_msg": "待机中"
},
{
"alarm_no": 204,
"alarm_type": "XXX",
"alarm_msg": "急停"
}
]
}
转换成
{
"cnc_alarm_1_msg": "待机中",
"cnc_alarm_1_no": 1,
"cnc_alarm_1_type": "T01",
"cnc_alarm_2_msg": "急停",
"cnc_alarm_2_no": 204,
"cnc_alarm_2_type": "XXX"
}
function calc(value)
for i, v in ipairs(value.cnc_alarm) do
['cnc_alarm_' .. i .. '_msg'] = v.alarm_msg
value['cnc_alarm_' .. i .. '_no'] = v.alarm_no
value['cnc_alarm_' .. i .. '_type'] = v.alarm_type
valueend
.cnc_alarm = nil
valuereturn value
end
6.4.6 将坐标的Array[Object]展开成普通变量
{
"cnc_mecpos": [
{
"axis": "X",
"value": -84.4
},
{
"axis": "Y",
"value": 2.986
},
{
"axis": "Z",
"value": -108.181
}
]
}
转换成
{
"cnc_mecpos_X": -84.4,
"cnc_mecpos_Y": 2.986,
"cnc_mecpos_Z": -108.181
}
function calc(value)
for i, v in ipairs(value.cnc_mecpos) do
['cnc_mecpos_'..v.axis]=v.value
valueend
.cnc_mecpos=nil
valuereturn value
end