PDA

View Full Version : Reading a Lua File into QHashes



ucntcme
23rd December 2009, 21:22
I'm working on an app that needs to read some "data" files written out in Lua (from World of Warcraft addons).

For reference the beginning of one of the file is here:

AucDbData = {
["bids"] = {
["US/Executus-Alliance"] = {
},
["US/Aggramar-Alliance"] = {
[1255128075] = "36909:0:0:0:823116736:20:Saggiebottom:180000:20000 0:0:4:list:200000;36909:0:0:0:1421360512:20:Saggie bottom:180000:200000:0:4:list:200000",
[1255166575] = "36907:0:0:0:727092128:7:Dionisis:57176:66528:0:4:l ist:66528;36907:0:0:0:897729472:13:Macamar:121550: 124800:0:4:list:124800",
[1255128605] = "36909:0:0:0:513886800:20:Saggiebottom:180000:20000 0:0:4:list:200000;36909:0:0:0:495964656:20:Saggieb ottom:180000:200000:0:4:list:200000",
[1255166698] = "36901:0:0:0:-2029754892:1:Hellstormi:4900:4900:0:4:list:4900;36 901:0:0:0:1483235840:5:Dionisis:33725:33725:0:4:li st:33725",
},
},
["count"] = {
["US/Aggramar-Alliance"] = {
["42411:0"] = {
[14526] = "83655:5:2880",
},
["41100:0"] = {
[14526] = "22862:1:2880",
},
["40922:0"] = {
[14526] = "13761:1:2880",
},
["12820:0"] = {
[14526] = "37600:2:1440",
},
["33461:0"] = {
[14526] = "2178:1:2880",
},
["43376:0"] = {
[14526] = "25643:1:2880",
},
["42910:0"] = {
[14526] = "19404:1:2880;19404:1:2880",
},
["43467:0"] = {
[14526] = "7821:1:2880",
},
},
},
["scans"] = {
["US/Executus-Alliance"] = {
},
["US/Aggramar-Alliance"] = {
[1255124278] = "12820:0:0:0:794027136:1:Azeract:17300:18400:0:4;12 820:0:0:0:1143618432:2:Thldruid:30100:30200:0:4",
(more lines like that one and it closes out)
....

Now it seems to me I have a few options. I could go the route of embedding a Lua interpreter and trying to access the data that way. I've looked but everything seems to be more about using Lua to access/control C++. I don't need to *do* anything in Lua, I'm just needing to read (only) in this data and then do stuff in Qt with it.

Which leads me to the option of writing a parser to read this data in and convert it to a nested QHash or custom object. I've seen references to QLALR that might be able to do the job but the only mentions of it are a couple years old and there is zero documentation.

Has anyone done something along either of these lines and be able to give references or pointers, or even just some advice as to routes to take? I've not written any parsers that do this soort of thing so it is a bit new to me. (But give me a log file ...). Theoretically I *could* use regexes but that doesn't smell right.

TorAn
24th December 2009, 04:05
Look at boost::spirit, may be it is what you are looking for.