Lua与XML进行数据存储 [英] Lua vs. XML for data storage

查看:236
本文介绍了Lua与XML进行数据存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们中的许多人都使用XML来存储数据。它的好处和缺点是众所周知的,我肯定不想在这里讨论他们。但是在项目中我使用C ++编写,我也使用Lua。我非常惊讶,Lua如何用来存储和处理数据。但是,Lua的这个方面至少在游戏编程世界中并不那么被认可。

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.

我知道XML在通过互联网发送数据的情况下有优势(例如使用从网络下载的数据,或加载用户可编辑的配置文件),最后在相同数据被不同语言的程序读取的情况下。

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.

然而,一旦我学会了使用Lua来处理数据(尤其是使用luabind来支持你)的方法,我开始怀疑是否有任何理由使用XML来存储游戏数据,如果我们已经使用Lua?

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在使用Lua编写UI时仍然使用XML存储布局。

Blizzard, while using Lua for scripting the UI, still stores the layout in XML. Is the reason something that is only UI related?

使用Lua作为数据存储语言的缺点是什么?

What are the drawbacks of using Lua as a data storage language?

推荐答案

这可能不是你期望的那种答案,但它可能会帮助你做出决定。

This might not be the kind of answer you expected, but it might help you make your decision.

Blizzard WoW)使用XML来定义UI。它很像C#中的XAML,只是不那么强大,大多数插件只是使用XML来引导插件,然后在lua代码中构建UI。

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.

实际上在.lua文件中存储了附件保存的变量。

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.

XML的好处是有很多工具和代码已经写入测试,写和解析XML,这意味着它可以节省您一些时间。例如, XML Schema 对于验证用户书写的文件非常有用(安全性只是一个副作用,好的事情是,如果它通过你的模式,数据很可能是100%安全,准备插入你的引擎),并有很多验证器已经写好供你使用。

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.

然后再次有些用户从XML文件(即使他们是非常可读,可能太可读)害怕,并喜欢更简单的东西。如果它只是为了存储(不是配置),那么没有人会在大多数情况下编辑这些文件。 XML也会占用更多的空间,然后lua var dump(不要紧,除非你有很多数据)。

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).

我不认为你可以在这里出错。暴雪使用lua存储,我很喜欢它的工作原理。

I don't think you can go wrong here. Blizzard is using lua for storage and I quite like like how it works.

这篇关于Lua与XML进行数据存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆