随笔 - 505  文章 - 1034  trackbacks - 0
<2007年6月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567


子曾经曰过:编程无他,唯手熟尔!

常用链接

留言簿(94)

随笔分类(649)

随笔档案(505)

相册

BCB

Crytek

  • crymod
  • Crytek's Offical Modding Portal

Game Industry

OGRE

other

Programmers

Qt

WOW Stuff

搜索

  •  

积分与排名

  • 积分 - 895437
  • 排名 - 14

最新随笔

最新评论

阅读排行榜

评论排行榜


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


posted on 2007-06-23 05:50 七星重剑 阅读(2415) 评论(2)  编辑 收藏 引用 所属分类: 乱七八糟

FeedBack:
# re: xml中嵌入lua 2007-06-25 11:45 yayv
wow里不就这样做的么
  回复  更多评论
  
# re: xml中嵌入lua 2007-07-03 06:52 阿来
@yayv
最爽的就是后来我知道了wow居然是这么做的,真是"英雄所见略同"!哈哈   回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理