这个EPGP World of Warcraft 插件输出一个 epgp.lua 数据库文件。
我编写了一个插件来将 Lua 数据转换为 JSON 对象以显示在公会网站上。它在旧版本的插件中工作,但现在我无法让它正确转换文件。以下是显示转换问题的两个片段 - 请参阅此演示。
第一个非常适合形成嵌套数组:
["roster_info"] = {
{
"Agantica", -- [1]
"ROGUE", -- [2]
"09/03-2013", -- [3]
}, -- [1]
{
"Intikamim", -- [1]
"PALADIN", -- [2]
"17/02-2013", -- [3]
}, -- [2]
},
变成
"roster_info" : [
[
"Agantica",
"ROGUE",
"09/03-2013"
],
[
"Intikamim",
"PALADIN",
"17/02-2013"
]
]
但是字符串替换将下一个片段视为嵌套数组,而它应该是数组内部的对象:
["bonus_loot_log"] = {
{
["player"] = "Magebox",
["timestamp"] = "2013-03-07 13:44:00",
["coinsLeft"] = "-1",
["reward"] = "|cffa335ee|Hitem:86815:0:0:0:0:0:0:632235520:90:0:445|h[Attenuating Bracers]|h|r",
}, -- [1]
{
["player"] = "Lîutasila",
["coinsLeft"] = "-1",
["timestamp"] = "2013-03-07 13:47:00",
}, -- [2]
},
变成
"bonus_loot_log" : [
[
"player" : "Magebox",
"timestamp" : "2013-03-07 13:44:00",
"coinsLeft" : "-1",
"reward" : "|cffa335ee|Hitem:86815:0:0:0:0:0:0:632235520:90:0:445|h[Attenuating Bracers]|h|r"
],
[
"player": "Lîutasila",
"coinsLeft": "-1",
"timestamp": "2013-03-07 13:47:00"
]
]
这是仅适用于第一个片段的字符串转换脚本。
lua_string
.replace(/\[(.*)\]\s\=\s/g,'$1:') // change equal to colon & remove outer brackets
.replace(/[\t\r\n]/g,'') // remove tabs & returns
.replace(/\}\,\s--\s\[\d+\]\}/g,']]') // replace sets ending with a comment with square brackets
.replace(/\,\s--\s\[\d+\]/g,',') // remove close subgroup and comment
.replace(/,(\}|\])/g,'$1') // remove trailing comma
.replace(/\}\,\{/g,'],[') // replace curly bracket set with square brackets
.replace(/\{\{/g,'[[') // change double curlies to square brackets
.replace(/EPGP_DB\s\=/,'');
所以,我需要一些帮助,让 Lua 正确转换对象数组(第二个示例)。