我将 Lua 与 IUP 一起使用,因此有许多对 IUP 句柄:
UseField1 = iup.toggle {blah blah blah}
Field1Label = iup.text {blah blah blah}
字段对 (maxFields) 的数量目前为 5,但可能会有所不同。
在我的 Lua 程序的各个地方,我需要执行以下操作:
for N in 1,maxFields do
If UseFieldN.value =="ON" then
DoSomethingWith(FieldNLabel.value, N)
end
end
我知道我不能构造动态变量名,但是有没有办法把它写成一个简洁的循环,而不是:
If UseField1 =="ON" then DoSomethingWith(Field1Label.value, 1) end
If UseField2 =="ON" then DoSomethingWith(Field2Label.value, 2) end
etc