There are probably more elegant ways of doing this, but facing the similar problem I've created the on_after_commit function for the map, where I checked the a and b values retrieved with uci and if any of them needed changing, updated them and then uci-save/uci-commit.
PS. You efforts to improve lua code may be short-lived, as there's a massive effort to remove any dependency on lua in the core code.
Thanks for response,
I have tried that several hooks - on_after_commit, on_before_commit, on_commit, on_apply, on_before_apply , But facing an issue there also,
actually its setting the value but somehow again its removing , when i run uci:change cammand then i got to know about that issue-
m.on_after_commit = function(self)
local a = m.uci:get("abc", arg[1], "a")
local b = m.uci:get("abc", arg[1], "b")
if a and b == nil then
m.uci:set("abc", arg[1], "b", a)
m.uci:save("abc")
m.uci:commit('abc')
return true
end
end
So, I have come up with the another solution by using formvalue() function
function o.formvalue(self, section)
local a = m:formvalue("cbid."..section..".a")
local b = m:formvalue("cbid."..section..".b")
if a and b == nil then
return a
else
return b
end
end
PS: I am just learner, just started to learn and explore the things.