can use lua as cofiguation data in cocos2d-x?anyone haven do this?can give me some tutorials or source code?
I used to use xml or json as config data.
I used like below:
local cfg
local function LoadConfig()
_,cfg = pcall(require, (APP_DOC_DIR or '')..'config')
if type(cfg) ~= 'table' then cfg = {} end
end
local function SaveConfig()
if not cfg then return end
local f = assert(io.open((APP_DOC_DIR or '')..'config.lua', "w"))
f:write('module(..., package.seeall) \n')
for k, v in pairs(cfg) do
if string.sub(k,1,1) ~= '_' then
local str = serialize(v)
if str then
f:write(k.."="..str.."\n")
end
end
end
f:close()
end
function CFG_SetParam(para1, value)
cfg[para1] = value or 1
SaveConfig()
end
function CFG_GetParam(para1)
return cfg[para1] or 0
end
LoadConfig()