Lua 改变配置文件内容

需要依赖库:libuci-lua

local uci = require 'uci'

local zconf = {}

--[[
cfile: 
"arn-omcd"

conf file: 
"/etc/config/arn-omcd"

config arn-omcd v3
    option server 192.168.1.4
    option proto 80
    option key1 "a1b2c3d4e5f6"
    option key2 "a6b5c4d3e2f1"

examples:
local key1 = conf.get("arn-omcd", "v3", "key1")
conf.set("arn-omcd", "v3", "interval", "30")
]]--

function zconf.get(cfile, sec, opt)
    if (uci) then
        if (cfile and sec and opt) then
            local uc = uci.cursor()
            result = uc:get(cfile, sec, opt)
        end
    end
    return nil
end

function zconf.set(cfile, sec, opt, val)
    if (uci) then
        if (cfile and sec and opt and val) then
            local uc = uci.cursor()
            uc:set(cfile, sec, opt, val)
            uc:commit(cfile)
        end
    end
end

return zconf

results matching ""

    No results matching ""