Many of us have been indoctrinated in using XML for storing data. It's benefits and drawbacks are generally known, and I surely don't want to discuss them here. However in the project I'm writing in C++, I'm also using Lua. I've been very surprised how well Lua can be used to store and handle data. Yet, this aspect of Lua is less recognized, at least in the game programming world.
I'm aware that XML has it's advantages in cases like sending data over the internet, and in places where safety comes into play (using data downloaded from the net for example, or loading user-editable configuration files) and finally in cases where the same data is being read by programs in different languages.
However once I learned how nice and easy it is to handle data using Lua (especially having luabind to back you up!), I started to wonder is there any reason to use XML to store game data, if we already use Lua anyway?
Blizzard, while using Lua for scripting the UI, still stores the layout in XML. Is the reason something that is only UI related?
What are the drawbacks of using Lua as a data storage language?
Thank you for your answers so far! I'll take the liberty of summing up the points for future reference.
Drawbacks of using Lua to store data, compared to XML
Benefits of using Lua to store data, compared to XML
If I missed something in the first list, please point it out!
This might not be the kind of answer you expected, but it might help you make your decision.
Blizzard (WoW) uses XML to define UI. It's kinda like XAML in C#, just a lot less powerful and most addons just use XML to bootstrap the addon and then build UI in lua code.
Also WoW actually stores addon "Saved Variables" in .lua files.
In my opinion it doesn't mater that much. Choose something you like and which is easy to use for those who are going to extend your engine.
The good thing about XML is that there are A LOT of tools and code already written to test, write and parse XML which means it could save you some time. For example XML Schema's are very useful for validating user written files (security is just a side effect, the good thing is that if it passes your schema, the data is most likely 100% safe and ready to be plugged into your engine) and there quite a few validators already written for you to use.
Then again some users are scared from XML files (even though they are very readable, maybe too readable) and would prefer something "simpler". If it's just for storage (not configuration) then no one is going to edit those file anyway in most cases. XML will also take more space then lua var dump (shouldn't matter, unless you have a lot data).
I don't think you can go wrong here. Blizzard is using lua for storage and I quite like like how it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With