require"config"
require"nvm"
module(...,package.seeall)

--[[

config.lua4
ÿβݷı󣬶ӡв
]]

local function print(...)
	_G.print("test",...)
end

local function getTablePara(t)
	if type(t)=="table" then
		local ret = "{"
		for i=1,#t do
			ret = ret..t[i]..(i==#t and "" or ",")
		end
		ret = ret.."}"
		return ret
	end
end

local function printAllPara()
	_G.print("\r\n\r\n")
	print("---printAllPara begin---")
	_G.print("strPara = "..nvm.get("strPara"))
	_G.print("numPara = "..nvm.get("numPara"))
	_G.print("boolPara = "..tostring(nvm.get("boolPara")))
	_G.print("tablePara = "..getTablePara(nvm.get("tablePara")))
	print("---printAllPara end  ---\r\n\r\n")
end

local function restoreFunc()
	print("restoreFunc")
	nvm.restore()
	printAllPara()
end

local function paraChangedInd(k,v,r)
	print("paraChangedInd",k,v,r)
    printAllPara()
	return true
end

local function tParaChangedInd(k,kk,v,r)
	print("tParaChangedInd",k,kk,v,r)
    printAllPara()
	return true
end

local procer =
{
	PARA_CHANGED_IND = paraChangedInd, --nvm.setӿ޸Ĳֵֵı䣬nvm.luasys.dispatchӿ׳PARA_CHANGED_INDϢ
	TPARA_CHANGED_IND = tParaChangedInd,	--nvm.settӿ޸table͵Ĳеĳһֵֵı䣬nvm.luasys.dispatchӿ׳TPARA_CHANGED_INDϢ
}
--עϢ
sys.regapp(procer)

--ʼģ
nvm.init("config.lua")

--ӡв
printAllPara()

--޸strParaֵΪstr2޸ĺnvm.luasys.dispatchӿ׳PARA_CHANGED_INDϢtest.luaӦôPARA_CHANGED_INDϢparaChangedInd(ע۲paraChangedIndдӡk,v,r)Զӡв
nvm.set("strPara","str2","strPara2")
--޸strParaֵΪstr3޸ĺȻstrParaֵstr3nvm.lua׳PARA_CHANGED_INDϢ
--Ϊnvm.setʱûд
--nvm.set("strPara","str3")
sys.timer_start(nvm.set,1000,"strPara","str3")

--޸numParaֵΪ2޸ĺnvm.luasys.dispatchӿ׳PARA_CHANGED_INDϢtest.luaӦôPARA_CHANGED_INDϢparaChangedInd(ע۲paraChangedIndдӡk,v,r)Զӡв
--nvm.set("numPara",2,"numPara2",false)
sys.timer_start(nvm.set,2000,"numPara",2,"numPara2",false)
--nvm.set("numPara",3,"numPara3",false)
sys.timer_start(nvm.set,3000,"numPara",3,"numPara3",false)
--nvm.set("numPara",4,"numPara4",false)
sys.timer_start(nvm.set,4000,"numPara",4,"numPara4",false)
--ִ3nvm.setnumParaֵձ4ڴб4ļд洢ʵϻ1ִһ󣬲Żȥдļϵͳ
nvm.flush()
--Ҳ˵nvm.setеĵ4Ƿдļϵͳfalseдļϵͳ඼дļϵͳĿúܶԼдļĴ

--ͬnvm.set("strPara","str2","strPara2")ԭ
--nvm.set("tablePara",{"item2-1","item2-2","item2-3"},"tablePara2")
sys.timer_start(nvm.set,5000,"tablePara",{"item2-1","item2-2","item2-3"},"tablePara2")
--ֻ޸tableParaеĵ2Ϊitem3-2
--nvm.sett("tablePara",2,"item3-2","tablePara3")
sys.timer_start(nvm.sett,6000,"tablePara",2,"item3-2","tablePara3")

--ָ,ӡв
sys.timer_start(restoreFunc,9000)
