Lua写配置文件
来源:互联网 发布:淘宝达人帖子范文 编辑:程序博客网 时间:2024/05/29 02:11
zc =
{
configTest =
{
sub = {A = 0, B = 1},
str = "I'm string!",
num = 4,
},
debug = false,
}
pcall(loadfile('luaConfig.lua'))
function write_table_to_file(prefix, tbl, luaConfig)
luaConfig = luaConfig or nil
local do_close = false
if luaConfig == nil then
luaConfig = io.open('luaConfig.lua', 'w')
do_close = true
end
for key,val in pairs(tbl) do
if type(val) == 'table' then
write_table_to_file(prefix .. '.' .. tostring(key), val, luaConfig)
else
if type(val) == 'string' then
val = '"' .. val .. '"'
end
msg = string.format('%s = %s', prefix .. '.' .. tostring(key), tostring(val) .. '\n')
luaConfig:write(msg)
end
end
if do_close then
luaConfig:close()
luaConfig = nil
print(luaConfig)
end
end
zc.debug = true
write_table_to_file('zc', zc)
{
configTest =
{
sub = {A = 0, B = 1},
str = "I'm string!",
num = 4,
},
debug = false,
}
pcall(loadfile('luaConfig.lua'))
function write_table_to_file(prefix, tbl, luaConfig)
luaConfig = luaConfig or nil
local do_close = false
if luaConfig == nil then
luaConfig = io.open('luaConfig.lua', 'w')
do_close = true
end
for key,val in pairs(tbl) do
if type(val) == 'table' then
write_table_to_file(prefix .. '.' .. tostring(key), val, luaConfig)
else
if type(val) == 'string' then
val = '"' .. val .. '"'
end
msg = string.format('%s = %s', prefix .. '.' .. tostring(key), tostring(val) .. '\n')
luaConfig:write(msg)
end
end
if do_close then
luaConfig:close()
luaConfig = nil
print(luaConfig)
end
end
zc.debug = true
write_table_to_file('zc', zc)
- Lua写配置文件
- Lua,Lua API,配置文件
- lua学习:lua作配置文件
- lua学习:lua作配置文件
- 写配置文件
- lua作配置文件
- Lua 配置文件示例
- lua当作配置文件
- 【cocos2dx 3.3 lua】09 lua配置文件读写
- lua 写文件io
- 写篇lua
- lua写排序算法
- 用lua写popStar
- c/c++解析lua配置文件
- LUA解析配置文件 简单实例
- c/c++解析lua配置文件
- Lua 作为配置文件(2)
- excel vba 导出lua配置文件
- shell 积累
- ScheduledExecutorService java 多线程
- 13:K-based Numbers
- prepare for the provincial time --9.2--Taxi Fare
- 今年清明
- Lua写配置文件
- OracleLinux下安装oracle11g的简易方法
- HDU 1250-Hat's Fibonacci
- .Net下Attribute的特性简单入门
- Android获取手机中所有应用程序和第三方程序
- 最大公共子字符串zz
- 10003 - Cutting Sticks
- VC 2008 Express下安装OpenCV2.3.1
- 如何在VC 6.0中编译.asm文件