• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

[转]xml中嵌入lua

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

http://www.cppblog.com/lai3d/archive/2007/06/23/26849.html

 

学xml   http://www.w3schools.com/xml/default.asp
我们游戏里界面和与界面有关的很多逻辑都是写在xml里面的,其中逻辑使用lua写,嵌在xml中,用xmlSpy编辑。
xml中嵌入lua,比如

<script>
function max(a,b)
    if a &gt; b then
        return a;
    else
        return b;
    end
end
</script>

大于号   > 要写成 &gt;  , 就是greater than的意思。同样:
小于号   <                &lt;            less than
这样子lua没有高亮显示,搞得我看起来很痛苦,晚上突发奇想,从*.lua文件里读,就可以用LuaEdit来编辑了,那我就可以按F6来check syntax了,哈哈

<script luafile="1" path="gui\haha.lua">
</script>

luafile 为 1,就读path里的,为0就读script节点的text,哈哈,爽!
我从xml文件中把lua段粘贴到*.lua文件里时,忘了把&gt;之类的符号换成 > 等,导致我查了很久,老子还跟踪到luabind和lua的源代码里面去,靠!faint!
幸亏LuaEdit有Check Syntax功能,帮助我检查到了错误,深刻体会到了工具的好处,也更加坚信“人与动物的最大差别在于人类能够制造工具并使用工具”!
要是再整得能单步调试,那就爽歪歪了!


All text in an XML document will be parsed by the parser.

Only text inside a CDATA section will be ignored by the parser.


Parsed Data

XML parsers normally parse all the text in an XML document.

When an XML element is parsed, the text between the XML tags is also parsed:

<message>This text is also parsed</message>

The parser does this because XML elements can contain other elements, as in this example, where the <name> element contains two other elements (first and last):

<name><first>Bill</first><last>Gates</last></name>

and the parser will break it up into sub-elements like this:

<name>
            <first>Bill</first>
            <last>Gates</last>
            </name>

Escape Characters

Illegal XML characters have to be replaced by entity references.

If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element. You cannot write something like this:

<message>if salary < 1000 then</message>

To avoid this, you have to replace the "<" character with an entity reference, like this:

<message>if salary &lt; 1000 then</message>

There are 5 predefined entity references in XML:

&lt;
<
less than

&gt;
>
greater than

&amp;
&
ampersand

&apos;
'
apostrophe

&quot;
"
quotation mark

Note: Only the characters "<" and "&" are strictly illegal in XML. Apostrophes, quotation marks and greater than signs are legal, but it is a good habit to replace them.


CDATA

Everything inside a CDATA section is ignored by the parser.

If your text contains a lot of "<" or "&" characters - as program code often does - the XML element can be defined as a CDATA section.

A CDATA section starts with "<![CDATA[" and ends with "]]>":

<script>
            <![CDATA[
            function matchwo(a,b)
            {
            if (a < b && a < 0) then
            {
            return 1
            }
            else
            {
            return 0
            }
            }
            ]]>
            </script>

In the example above, everything inside the CDATA section is ignored by the parser.

Notes on CDATA sections:

A CDATA section cannot contain the string "]]>", therefore, nested CDATA sections are not allowed.

Also make sure there are no spaces or line breaks inside the "]]>" string.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
一个简单的Lua解释器发布时间:2022-07-22
下一篇:
轻量级Lua IDE ZeroBrane Studio 的使用技巧和汉化发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap