zoukankan      html  css  js  c++  java
  • [转]xml中嵌入lua

    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.

  • 相关阅读:
    Maven+JSP+Servlet+JDBC+Redis+Mysql实现的黑马旅游网
    Thymeleaf+SpringBoot+SpringDataJPA实现的中小医院信息管理系统
    Thymeleaf+SpringBoot+Mybatis实现的家庭财务管理系统
    JSP+Struts2+JDBC+Mysql实现的校园宿舍管理系统
    JSP+SSH+Mysql+C3P0实现的传智播客网上商城
    JSP+SSH+Mysql实现的学生管理系统
    JSP+Servlet+C3P0+Mysql实现的简单新闻系统
    笔记:EF出现列名 'Discriminator' 无效、类没有加入数据库上下文也被数据迁移生成表
    判断字符串中是否存在的几种方案:string.indexof、string.contains、list.contains、list.any几种方式效率对比
    Sql server 中关闭ID自增字段(SQL取消ID自动增长)
  • 原文地址:https://www.cnblogs.com/pulas/p/2506713.html
Copyright © 2011-2022 走看看