﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-woaidongmao-随笔分类-脚本语言</title><link>http://www.cppblog.com/woaidongmao/category/11554.html</link><description>文章均收录自他人博客，但不喜标题前加-[转贴]，因其丑陋，见谅！~</description><language>zh-cn</language><lastBuildDate>Tue, 10 May 2011 14:06:49 GMT</lastBuildDate><pubDate>Tue, 10 May 2011 14:06:49 GMT</pubDate><ttl>60</ttl><item><title>数据/配置 的存储方式 Lua篇</title><link>http://www.cppblog.com/woaidongmao/archive/2010/12/28/137601.html</link><dc:creator>肥仔</dc:creator><author>肥仔</author><pubDate>Tue, 28 Dec 2010 05:06:00 GMT</pubDate><guid>http://www.cppblog.com/woaidongmao/archive/2010/12/28/137601.html</guid><wfw:comment>http://www.cppblog.com/woaidongmao/comments/137601.html</wfw:comment><comments>http://www.cppblog.com/woaidongmao/archive/2010/12/28/137601.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/woaidongmao/comments/commentRss/137601.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/woaidongmao/services/trackbacks/137601.html</trackback:ping><description><![CDATA[<p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">前言<span lang="EN-US"><?xml:namespace prefix = o /><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span></span><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">在《数据<span lang="EN-US">/</span>配置 的存储方式<span lang="EN-US"> Json</span>篇 以<span lang="EN-US">JsonCpp</span>库使用为例》《数据<span lang="EN-US">/</span>配置 的存储方式<span lang="EN-US"> Json</span>篇 以<span lang="EN-US">Cocos2D For Iphone+TouchJson</span>为例 》中我总结了一下怎么使用<span lang="EN-US">Json</span>作为配置，但是，其实<span lang="EN-US">Json</span>虽然语法格式简单，同时解析库的使用也非常简单，但是，因为这种简单性，缺少有的时候的确非常需要的功能。比如配置文件中对另一行配置的引用，比如配置段的继承等，这些可以使用<span lang="EN-US">XML</span>来解决，另外，有的时候还会需要在配置文件中进行简单的运算，比如我就常常会有想将某个图片缩放到目前分辨率的几分之几这样的需求，此时，用一个完整的可以进行运算的语言来做配置的诱惑实在太大了。。。。。。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>Lua</span><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">就是为此而生的。。。。。。虽然现在<span lang="EN-US">Lua</span>的功能已经远远不止这样了，但是最初设计<span lang="EN-US">Lua</span>的目的就是一个简单的配置语言。见<span lang="EN-US">Lua</span>的历史 。虽然其实用<span lang="EN-US">Python</span>作为配置也完全可行，但是<span lang="EN-US">Lua</span>有着速度快的优点，而且，<span lang="EN-US">Lua</span>实在比<span lang="EN-US">Python</span>小太多了，很适合嵌入到程序中去。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">对于使用<span lang="EN-US">Lua</span>作为配置，事实上就相当于在<span lang="EN-US">C++</span>中嵌入<span lang="EN-US">Lua</span>，只不过不用其脚本语言的一些复杂特性，仅仅将其作为一个配置文件来看。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">这里还是以原来《数据<span lang="EN-US">/</span>配置 的存储方式<span lang="EN-US"> Json</span>篇 以<span lang="EN-US">JsonCpp</span>库使用为例》文中开始的<span lang="EN-US">SDL</span>工程作为例子。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">首先搭建可以内嵌使用<span lang="EN-US">Lua</span>的<span lang="EN-US">C++</span>编译环境，下载一个<span lang="EN-US">luabinaries </span>是简单的办法，现在我使用的是<span lang="EN-US">lua5_1_4_Win32_dll8_lib.zip </span>。这里我甚至不需要一个可以运行的<span lang="EN-US">Lua</span>交互环境。。。。。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">简单示例<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">首先建立一个简单的<span lang="EN-US">Lua</span>文件<span lang="EN-US">,</span>命名为<span lang="EN-US">picture.lua<o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">name="dragon.png" <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">rotation=180 <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">虽然只有简单的两行，也是个合法的<span lang="EN-US">Lua</span>程序。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">然后在<span lang="EN-US">C++</span>程序中读取出来，这个过程实际上是使用了<span lang="EN-US">Lua</span>的<span lang="EN-US">C API</span>，具体的<span lang="EN-US">Lua</span>的<span lang="EN-US">C API</span>这里就不详细讲解了，那比较复杂，可以参考《<span lang="EN-US">Programming in Lua</span>》，中文版也已经有了。这里仅仅作为一个例子提供参考吧。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">现在可以开始完成<span lang="EN-US">C++</span>的程序了：<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">首先，包含必要的头文件：<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">extern "C" {<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">#include "lua/lua.h"<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">#include "lua/lauxlib.h"<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">#include "lua/lualib.h"<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">}<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">因为<span lang="EN-US">lua</span>的头文件完全是只考虑<span lang="EN-US">C</span>语言的情况，所以在<span lang="EN-US">C++</span>中使用的时候需要自己添加<span lang="EN-US">extern "C"</span>。这是典型的对<span lang="EN-US">C++</span>不屑的态度，因为现在大部分的纯<span lang="EN-US">C</span>语言写的库，都会很自然的通过宏判断来自动使用<span lang="EN-US">extern "C"</span>语句。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">然后：<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">using<span style="mso-spacerun: yes">&nbsp; </span>namespace<span style="mso-spacerun: yes">&nbsp; </span>std;<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">struct<span style="mso-spacerun: yes">&nbsp;&nbsp; </span>PictureInfo {<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>string name;<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>float<span style="mso-spacerun: yes">&nbsp; </span>rotation;<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">}gPictureInfo;<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">void<span style="mso-spacerun: yes">&nbsp;&nbsp; </span>PictureInit() {<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>lua_State *L = luaL_newstate();<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>if ( luaL_dofile(L, "picture.lua" ) != 0 ) {<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>printf("Error happen." );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>// handle the error. <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>exit(1 );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>}<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>lua_getglobal(L, "name" );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>assert(lua_isstring(L, -1 ) == 1 );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>gPictureInfo.name = lua_tostring(L, -1 );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>lua_getglobal(L, "rotation" );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>gPictureInfo.rotation = (float )lua_tonumber(L, -1 );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>lua_close(L);<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">}<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">这里我们使用的所有变量全部都是<span lang="EN-US">global</span>的变量，所以调用起来非常方便。上面的主要内容就是对<span lang="EN-US">Lua C API</span>的使用，由于其本身较为复杂，这里一下也讲不清楚。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">基本流程是创建新的<span lang="EN-US">Lua state,</span>然后用<span lang="EN-US">luaL_dofile </span>执行我们需要的配置文件，然后调用<span lang="EN-US">lua_getglobal </span>加适当的转换来获取我们需要的配置值。这里的例子是一个字符串和一个浮点数。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">具体显示的效果和其他代码参考《数据<span lang="EN-US">/</span>配置 的存储方式<span lang="EN-US"> Json</span>篇 以<span lang="EN-US">JsonCpp</span>库使用为例》就好了，这里不重复描述了。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">数组<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span></span><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">在<span lang="EN-US">Lua</span>中数组也通过<span lang="EN-US">table</span>的形式来表示，这里我仅仅介绍怎么从<span lang="EN-US">lua</span>文件中获取配置，具体的显示等东西也不再累述了。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span></span><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">这里，我们建立一个包含数组的<span lang="EN-US">lua</span>文件作为配置：<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">data = { <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<span style="mso-spacerun: yes">&nbsp; </span>name="dragon.png" , rotation=180<span style="mso-spacerun: yes">&nbsp; </span>} ,<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<span style="mso-spacerun: yes">&nbsp; </span>name="dragon.png" , rotation=0<span style="mso-spacerun: yes">&nbsp; </span>} <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">} <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">下面看怎么将配置读取出来：<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">using<span style="mso-spacerun: yes">&nbsp; </span>namespace<span style="mso-spacerun: yes">&nbsp; </span>std;<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">struct<span style="mso-spacerun: yes">&nbsp;&nbsp; </span>PictureInfo {<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>string name;<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>float<span style="mso-spacerun: yes">&nbsp; </span>rotation;<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">};<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">vector gPictureInfoVec;<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">void<span style="mso-spacerun: yes">&nbsp;&nbsp; </span>PictureInit() {<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>lua_State *L = luaL_newstate();<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>if ( luaL_dofile(L, "picture.lua" ) != 0 ) {<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>printf("Error happen." );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>// handle the error. <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>exit(1 );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>}<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>// get the table <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>lua_getglobal(L, "data" );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>assert(lua_istable(L, -1 ) == 1 );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>/*<span style="mso-spacerun: yes">&nbsp; </span>table is in the stack at index 't' */ <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>lua_pushnil(L);<span style="mso-spacerun: yes">&nbsp; </span>/*<span style="mso-spacerun: yes">&nbsp; </span>first key */ <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>while<span style="mso-spacerun: yes">&nbsp; </span>(lua_next(L, -2 ) != 0 ) {<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>PictureInfo info;<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>/* 'key' (at index -2) and 'value' (at index -1) */ <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>// push the key to stack for getting the value <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>lua_pushstring(L, "name" );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>// now the table is in the -2 and key in the top(-1) <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>lua_gettable(L, -2 );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>assert(lua_isstring(L, -1 ));<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>info.name = lua_tostring(L, -1 );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>lua_pop(L, 1 );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>// push the key to stack for getting the value <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>lua_pushstring(L, "rotation" );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>// now the table is in the -2 and key in the top(-1) <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>lua_gettable(L, -2 );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>assert(lua_isnumber(L, -1 ));<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>info.rotation = lua_tonumber(L, -1 );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>gPictureInfoVec.push_back(info);<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>/*<span style="mso-spacerun: yes">&nbsp; </span>removes the key we pushed and the 'value' of the global table ;<span style="mso-spacerun: yes">&nbsp;&nbsp; </span>keeps 'key' for next iteration */ <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>lua_pop(L, 2 );<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>}<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span>lua_close(L);<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">}<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">代码中的注释解释的已经够详细了，但是因为<span lang="EN-US">Lua </span>的<span lang="EN-US">API</span>的确不是太容易理解，这里也无法一下讲清楚，所以还是先了解<span lang="EN-US">Lua </span>的<span lang="EN-US"> API</span>为好，具体的<span lang="EN-US">API</span>的意义可以参考参考手册。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">上面仅仅使用了<span lang="EN-US">Lua API</span>遍历数组以及从<span lang="EN-US">table</span>中获取元素的方法。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">假如仅仅只有上面这些，是看不出用<span lang="EN-US">lua</span>作为配置的好处的，用<span lang="EN-US">lua</span>做配置的好处在于可以利用<span lang="EN-US">lua</span>的特性实现配置段之间的继承以及完整的运算功能。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">比如说，完全不用修改上面的读取配置的代码，我们仅仅修改配置，看看在<span lang="EN-US">Lua</span>中使用上述功能：<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">data1 = {<span style="mso-spacerun: yes">&nbsp; </span>name="dragon.png" , rotation=180<span style="mso-spacerun: yes">&nbsp; </span>} <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">data2 = {<span style="mso-spacerun: yes">&nbsp; </span>name = data1.name, rotation = data1.rotation / 2 } <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">data = { <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>data1, data2<o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US">} <o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">此时，<span lang="EN-US">data2</span>的数据完全依赖于<span lang="EN-US">data1</span>的数据，当有任何东西需要修改的时候，你只需要修改一个地方，对于配置来说，<span lang="EN-US">don't repeat yourself</span>也是很有意义的。最最重要的的是，在配置中能够进行计算那是非常强大，即使完全不用<span lang="EN-US">lua</span>的函数功能与代码的交互，仅仅通过<span lang="EN-US">lua</span>的计算，也可以完成游戏中所有<span lang="EN-US">sprite</span>的布局。。。。。。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">小结<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span></span><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">相对于使用<span lang="EN-US">XML,Json</span>，使用<span lang="EN-US">Lua</span>作为配置绝对是最最强大的。。。。。。作为一个完整的语言，它拥有你想在配置中实现的一切功能。但是缺点也是很明显的：<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp; </span><span style="mso-spacerun: yes">&nbsp; </span></span><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">首先，速度上，<span lang="EN-US">Lua</span>需要解释运行，可能明显跟不上<span lang="EN-US">XML</span>或者<span lang="EN-US">Json</span>的解析速度。但是，配置的解析读取可以都放在初始化阶段，所以配置不是太多的时候，也不算太过难以接受，另外，还可以将<span lang="EN-US">lua</span>的配置完全作为开发期的一种机制使用，在发布后完全转化为<span lang="EN-US">2</span>进制数据。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span></span><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">其次，<span lang="EN-US">Lua</span>的配置读取需要手动调用<span lang="EN-US">Lua</span>的<span lang="EN-US">API</span>来完成，相对于<span lang="EN-US">XML</span>，<span lang="EN-US">Json</span>那种有很方便的库的情况，使用上还是麻烦一些，特别是<span lang="EN-US">Lua</span>的<span lang="EN-US">API</span>的使用并不是那么简单易懂，不算太直观。但是，这也不是不可以克服的，完全可以自己写个小型的库将<span lang="EN-US">Lua</span>的<span lang="EN-US">API</span>封装起来，形成一个类似<span lang="EN-US">JsonCpp</span>那样的库，用<span lang="EN-US">Map</span>来表示一切。这个可能需要限制一些<span lang="EN-US">Lua</span>语法的时候，或者在解析的时候进行取舍，比如函数啥的可能需要过滤掉，不然那就不太像将<span lang="EN-US">Lua</span>作为配置使用了。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span></span><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">还有，<span lang="EN-US">Lua</span>的配置的生成更加是没有<span lang="EN-US">XML,Json</span>那样有完善库支持来的方便，这点暂时没有办法克服，写一个自动生成<span lang="EN-US">Lua</span>配置文件的库感觉并不是太过容易的事情。而且，自动生成时，<span lang="EN-US">lua</span>的优势其实并没有余地发挥出来，那样的话，还不如使用<span lang="EN-US">Json</span>。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span></span><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">总的来说，假如是没有工具，需要大量手写配置的话，对<span lang="EN-US">Lua</span>的<span lang="EN-US">API</span>进行一层简单的封装，然后使用<span lang="EN-US">Lua</span>来做配置，那还是件很爽的事情，需要手写的时候，你才会感觉到一个完整语言作为配置给你带来的好处。<span lang="EN-US"><o:p></o:p></span></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial">本文来自<span lang="EN-US">CSDN</span>博客，转载请标明出处：<span lang="EN-US">http://blog.csdn.net/vagrxie/archive/<?xml:namespace prefix = st1 /><st1:chsdate w:st="on" isrocdate="False" islunardate="False" day="23" month="7" year="2010">2010/07/23</st1:chsdate>/5758521.aspx<o:p></o:p></span></span></p><img src ="http://www.cppblog.com/woaidongmao/aggbug/137601.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/woaidongmao/" target="_blank">肥仔</a> 2010-12-28 13:06 <a href="http://www.cppblog.com/woaidongmao/archive/2010/12/28/137601.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一个C++读取Lua配置文件的例子</title><link>http://www.cppblog.com/woaidongmao/archive/2010/12/28/137600.html</link><dc:creator>肥仔</dc:creator><author>肥仔</author><pubDate>Tue, 28 Dec 2010 05:05:00 GMT</pubDate><guid>http://www.cppblog.com/woaidongmao/archive/2010/12/28/137600.html</guid><wfw:comment>http://www.cppblog.com/woaidongmao/comments/137600.html</wfw:comment><comments>http://www.cppblog.com/woaidongmao/archive/2010/12/28/137600.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/woaidongmao/comments/commentRss/137600.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/woaidongmao/services/trackbacks/137600.html</trackback:ping><description><![CDATA[<p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; color: black; font-size: 12pt" lang="EN-US">//LuaEx.h</span><span style="line-height: 150%; font-family: 宋体; color: black; font-size: 12pt">文件<span lang="EN-US"><br><br>#pragma once<br>#include &lt;Windows.h&gt;<br>extern "C"<br>{<br>#include "lua/lua.h"<br>#include "lua/lualib.h"<br>#include "lua/lauxlib.h"<br>};<br><br>class LuaEx<br>{<br>public:<br>LuaEx(void);<br>~LuaEx(void);<br>bool LoadFile(LPCSTR str); //</span>载入<span lang="EN-US">lua</span>文件<span lang="EN-US"><br>LPSTR LoadString(LPCSTR str); //</span>读取字符串<span lang="EN-US"><br>int LoadInteger(LPCSTR str); //</span>读取整形<span lang="EN-US"><br>double LoadDouble(LPCSTR str); //</span>读取浮点型<span lang="EN-US"><br>bool LoadBoolean(LPCSTR str); //</span>读取布尔型<span lang="EN-US"><br><br>private:<br>lua_State *L; //lua</span>指针<span lang="EN-US"><br>};<br><br>//LuaEx.cpp</span>文件<span lang="EN-US"><br><br>#include ".\luaex.h"<br>#pragma comment(lib, ".\\lua\\lua.lib")<br><br>LuaEx::LuaEx(void)<br>{<br>L = lua_open();<br>luaL_openlibs(L);<br>}<br><br>LuaEx::~LuaEx(void)<br>{<br>lua_close(L);<br>}<br><br>bool LuaEx::LoadFile(LPCSTR str)<br>{<br>if(luaL_dofile(L, str))<br>{<br>return false;<br>}<br>return true;<br>}<br><br>LPSTR LuaEx::LoadString(LPCSTR str)<br>{<br>lua_getglobal(L, str);<br>if (lua_isstring(L, -1))<br>{<br>return (LPSTR)lua_tostring(L, -1);<br>}<br>return NULL;<br>}<br><br>int LuaEx::LoadInteger(LPCSTR str)<br>{<br>lua_getglobal(L, str);<br>if (lua_isnumber(L, -1))<br>{<br>return (int)lua_tointeger(L, -1);<br>}<br>return NULL;<br>}<br><br>double LuaEx::LoadDouble(LPCSTR str)<br>{<br>lua_getglobal(L, str);<br>if (lua_isnumber(L, -1))<br>{<br>return (double)lua_tonumber(L, -1);<br>}<br>return 0.0;<br>}<br><br>bool LuaEx::LoadBoolean(LPCSTR str)<br>{<br>lua_getglobal(L, str);<br>if (lua_isboolean(L, -1))<br>{<br>return (bool)lua_toboolean(L, -1);<br>}<br>return false;<br>}<br><br><br></span>在要使用配置文件的地方实例化一个<span lang="EN-US">LuaEx</span>类就可以了。<span lang="EN-US"><br></span>先调用<span lang="EN-US">LoadFile</span>载入文件，参数为文件路径。文件格式可以按照如下方式：<span lang="EN-US"><br><br>title = "</span>游戏<span lang="EN-US">"<br>width = 640<br>height = 480<br>isWindowed = true;<br>useSound = false;<br>hideMouse = false;<br><br></span>结尾分号可加可不加，就是写一个<span lang="EN-US">lua</span>脚本，但是只包含变量不包含方法。<span lang="EN-US"><br></span>之后就可以读取其中内容了。例如<span lang="EN-US"><br>LoadString("title"); //</span>表示载入变量名为<span lang="EN-US">title</span>的变量的值。<span lang="EN-US"><br></span>本类中所有函数的参数都是字符串。</span><span style="line-height: 150%; font-family: 宋体; color: black; font-size: 12pt; mso-bidi-font-family: 宋体" lang="EN-US"><?xml:namespace prefix = o /><o:p></o:p></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; color: black; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><o:p>&nbsp;</o:p></span></p><img src ="http://www.cppblog.com/woaidongmao/aggbug/137600.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/woaidongmao/" target="_blank">肥仔</a> 2010-12-28 13:05 <a href="http://www.cppblog.com/woaidongmao/archive/2010/12/28/137600.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>c++调用lua例子</title><link>http://www.cppblog.com/woaidongmao/archive/2010/12/27/137556.html</link><dc:creator>肥仔</dc:creator><author>肥仔</author><pubDate>Mon, 27 Dec 2010 04:57:00 GMT</pubDate><guid>http://www.cppblog.com/woaidongmao/archive/2010/12/27/137556.html</guid><wfw:comment>http://www.cppblog.com/woaidongmao/comments/137556.html</wfw:comment><comments>http://www.cppblog.com/woaidongmao/archive/2010/12/27/137556.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/woaidongmao/comments/commentRss/137556.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/woaidongmao/services/trackbacks/137556.html</trackback:ping><description><![CDATA[<p>&nbsp; <p><a title="http://blog.csdn.net/bhwst/archive/2010/07/29/5774746.aspx" href="http://blog.csdn.net/bhwst/archive/2010/07/29/5774746.aspx">http://blog.csdn.net/bhwst/archive/2010/07/29/5774746.aspx</a> <p>&nbsp; <p>VC要编译LUA文件必须先配置VC编程环境。。我用的是VC6.0，lua 5.1.4版 <p>首先将lua的"lua.h" ，"lualib.h"， "lauxlib.h" 这三个放在vc程序include文件夹下 <p>然后将lua的lua5.1.lib放在lib文件夹下就OK了 <p>下面看看我写的一个小例子： <p>a.cpp <p>view plaincopy to clipboardprint? <p>#include "windows.h" <p>extern "C"{ <p>#include "lua.h"  <p>#include "lualib.h" <p>#include "lauxlib.h" <p>} <p>#pragma comment(lib,"lua5.1.lib") <p>lua_State * L; <p>static int clib(lua_State *L) //给lua调用的c函数必须定义成static int XXX(lua_State *L) <p>{ <p>char path[MAX_PATH]; <p>GetCurrentDirectory(MAX_PATH,path); <p>lua_pushstring(L,path); <p>return 1; //为什么要返回1？这是有依据的，该函数把结果压入了栈，lua调用该函数将从栈中 <p>//取1个结果 <p>} <p>int main ( int argc, char *argv[] ) <p>{ <p>int sum; <p>//创建一个指向lua解释器的指针 <p>L = luaL_newstate(); <p>//加载lua标准库 <p>luaL_openlibs(L); <p>//注册C++函数 <p>lua_register(L,"clib",clib); <p>//加载脚本 <p>luaL_dofile(L,"4.lua"); <p>//调用函数 <p>lua_getglobal(L,"run"); <p>//运行函数并把结果压入栈 <p>lua_pcall(L,0,0,0); <p>//关闭并释放资源 <p>lua_close(L); <p>return 0; <p>} <p>#include "windows.h" <p>extern "C"{  <p>#include "lua.h" <p>#include "lualib.h" <p>#include "lauxlib.h"  <p>} <p>#pragma comment(lib,"lua5.1.lib") <p>lua_State * L; <p>static int clib(lua_State *L) //给lua调用的c函数必须定义成static int XXX(lua_State *L) <p>{ <p>char path[MAX_PATH];  <p>GetCurrentDirectory(MAX_PATH,path); <p>lua_pushstring(L,path); <p>return 1; //为什么要返回1？这是有依据的，该函数把结果压入了栈，lua调用该函数将从栈中 <p>//取1个结果 <p>} <p>int main ( int argc, char *argv[] ) <p>{ <p>int sum; <p>//创建一个指向lua解释器的指针 <p>L = luaL_newstate(); <p>//加载lua标准库 <p>luaL_openlibs(L); <p>//注册C++函数 <p>lua_register(L,"clib",clib); <p>//加载脚本 <p>luaL_dofile(L,"4.lua"); <p>//调用函数 <p>lua_getglobal(L,"run"); <p>//运行函数并把结果压入栈 <p>lua_pcall(L,0,0,0); <p>//关闭并释放资源 <p>lua_close(L); <p>return 0; <p>} <p>4.lua文件 <p>view plaincopy to clipboardprint? <p>function run() <p>print("call running from c") <p>print(clib()) <p>end <p>function run() <p>print("call running from c") <p>print(clib()) <p>end <p>这个例子实现了C与lua的相互调用。。另外，还可以把我前面一篇lua调用C dll的内容整合在一起。。 <p>本文来自CSDN博客，转载请标明出处：http://blog.csdn.net/bhwst/archive/2010/07/29/5774746.aspx <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial"><span lang="EN-US"><?xml:namespace prefix = o /><o:p></o:p></span></span></p><img src ="http://www.cppblog.com/woaidongmao/aggbug/137556.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/woaidongmao/" target="_blank">肥仔</a> 2010-12-27 12:57 <a href="http://www.cppblog.com/woaidongmao/archive/2010/12/27/137556.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Lua调用C DLL</title><link>http://www.cppblog.com/woaidongmao/archive/2010/12/27/137555.html</link><dc:creator>肥仔</dc:creator><author>肥仔</author><pubDate>Mon, 27 Dec 2010 04:56:00 GMT</pubDate><guid>http://www.cppblog.com/woaidongmao/archive/2010/12/27/137555.html</guid><wfw:comment>http://www.cppblog.com/woaidongmao/comments/137555.html</wfw:comment><comments>http://www.cppblog.com/woaidongmao/archive/2010/12/27/137555.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/woaidongmao/comments/commentRss/137555.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/woaidongmao/services/trackbacks/137555.html</trackback:ping><description><![CDATA[<p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial" lang="EN-US"><a title="http://blog.csdn.net/bhwst/archive/2010/07/22/5756441.aspx" href="http://blog.csdn.net/bhwst/archive/2010/07/22/5756441.aspx">http://blog.csdn.net/bhwst/archive/2010/07/22/5756441.aspx</a></span></p> <p style="line-height: 150%" class="MsoNormal"><span style="line-height: 150%; font-family: 宋体; font-size: 12pt; mso-bidi-font-family: arial"><span lang="EN-US"><?xml:namespace prefix = o /><o:p></o:p></span></span></p><img src ="http://www.cppblog.com/woaidongmao/aggbug/137555.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/woaidongmao/" target="_blank">肥仔</a> 2010-12-27 12:56 <a href="http://www.cppblog.com/woaidongmao/archive/2010/12/27/137555.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>lua5.1.dll 和 lua51.dll</title><link>http://www.cppblog.com/woaidongmao/archive/2010/12/27/137552.html</link><dc:creator>肥仔</dc:creator><author>肥仔</author><pubDate>Mon, 27 Dec 2010 04:37:00 GMT</pubDate><guid>http://www.cppblog.com/woaidongmao/archive/2010/12/27/137552.html</guid><wfw:comment>http://www.cppblog.com/woaidongmao/comments/137552.html</wfw:comment><comments>http://www.cppblog.com/woaidongmao/archive/2010/12/27/137552.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/woaidongmao/comments/commentRss/137552.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/woaidongmao/services/trackbacks/137552.html</trackback:ping><description><![CDATA[<p>今天下载lua的Windows二进制发布luabinaries 的时候，发现luabinaries的发布包含两个dll,lua5.1.dll,lua51.dll，其中lua5.1.dll大小合适，lua51.dll只有11K，感觉不像是个有用的lua dll，对此比较不解，查看了luabinaries的文档，<br>文档中如此解释：<br>The LuaBinaries DLL packages have a dll proxy called "lua51.dll". It can be used to replace other "lua51.dll" released by other distributions. It will simply forward calls to the "lua5.1.dll". There is no compiled source code involved in the forwarding.<br>也就是说，lua51.dll完全是一个lua5.1.dll的代理类，没有任何实际的代码，仅仅是做一个到lua5.1.dll的forwarding。<br>&nbsp;&nbsp;&nbsp; 不过文档解释了lua51.dll是什么，却没有解释为啥会需要一个这样的东西呢？我还从来没有见过类似的情况。要说有一点点类似的情况的话，也是以前做反外挂的时候，知道可以通过替换现有的dll，并且完全模拟原来dll的接口，并将不需要hack的函数全部forwarding到原来的dll中。对于lua怎么会需要这样的功能呢？<br>于是我google了一下，发现了原因：<br>The standard DLL name "lua51.dll" has been selected more than<br>three years ago. Around twice every year someone comes along and<br>thinks "Oh, we absolutely need a dot in the DLL version number".
<p>Alas, Windows does not like an extra dot in there. Many things<br>break when you have an extra dot in DLL names. Depends on the<br>version of the OS, on the specific system call, on the library or<br>tool used ... it's hopeless. So please let's forget about it.
<p>--Mike<br>来自lua-users.org的一个帖子 。<br>原来是3年前有人确定了一个lua51.dll名字的动态库，并且，有人觉得我们非常需要在5和1之间加一个点，不然lua的5.1版岂不是看成lua的51版了？<br>对此，有人进一步提出了疑问 ，认为这个问题怎么这么久了竟然没有人修复？<br>接着有人回答了：<br>But who's duty is to resolve the issue?
<p>It's clearly not an issue of Lua as a language. It's just a consequence of (a very popular) LuaBinaries once releasing lua5.1.dll that became a de facto binary standard, then authors of many third-party Lua libraries were releasing binary packages compatible with LuaBinaries. <br>Note: I'm not blaming LuaBinaries; that was just one unfortunate decision that is difficult to be undone. --<br>Shmuel
<p>我们知道了：<br>LuaBinaries做出了一个错误的决定，但是已经发布了，很多第3方的库也发布了，并且依赖于LuaBinaries的这个lua51.dll，于是：<br>that was just one unfortunate decision that is difficult to be undone. <br>那仅仅是一个过去做下，现在难以撤销的不幸决定。。。。。。。。。。。。
<p>&nbsp;&nbsp;&nbsp; 有的东西存在了，即使是不合理的存在，因为它存在了一段时间了，因为惯性，它还会存在在那里。编程中，这种情况经常出现。突然让我想起上个项目中，大家经常对项目中蹩脚代码存在原因的解释：&#8220;历史原因&#8221;。<br>&nbsp;&nbsp;&nbsp; 对于代码来说，即使大家都知道可以重构，但是重构是有代价的，很多时候大家就妥协在历史原因当中。<br>&nbsp;&nbsp;&nbsp; 对于语言来说，C++就是对历史进行最大妥协而产生的语言，大家都承认，假如当年C++不兼容C的话，C++根本就得不到现在这样的流行程度，也都承认，因为C++兼容C，（常常被称为历史的包袱）C++在语言的优美程度上损失了太多。<br>&nbsp;&nbsp;&nbsp; 想起国内某个大牛有过类似的感慨，&#8220;现在每做一个设计决定的时候都非常小心，因为那可能会被使用非常非常长的时间，当它还能正常工作的时候，甚至不会有人想要去重写它&#8220;<br>&nbsp;&nbsp;&nbsp; 呵呵，仅仅将这个有趣的事件作为编程中的一个轶事来看吧。
<p>本文来自CSDN博客，转载请标明出处：http://blog.csdn.net/vagrxie/archive/2010/07/23/5756804.aspx</p>
<img src ="http://www.cppblog.com/woaidongmao/aggbug/137552.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/woaidongmao/" target="_blank">肥仔</a> 2010-12-27 12:37 <a href="http://www.cppblog.com/woaidongmao/archive/2010/12/27/137552.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在C++中应用Google Chrome脚本引擎&amp;mdash;&amp;mdash;V8</title><link>http://www.cppblog.com/woaidongmao/archive/2010/05/17/115578.html</link><dc:creator>肥仔</dc:creator><author>肥仔</author><pubDate>Mon, 17 May 2010 04:25:00 GMT</pubDate><guid>http://www.cppblog.com/woaidongmao/archive/2010/05/17/115578.html</guid><wfw:comment>http://www.cppblog.com/woaidongmao/comments/115578.html</wfw:comment><comments>http://www.cppblog.com/woaidongmao/archive/2010/05/17/115578.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/woaidongmao/comments/commentRss/115578.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/woaidongmao/services/trackbacks/115578.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 原文地址：http://www.codeproject.com/KB/library/Using_V8_Javascript_VM.aspx  介绍 谁不想知道虚拟机是怎样工作的？不过，比起自己写一个虚拟机，更好的办法是使用大公司的产品。在这篇文章中，我将介绍如何在你的程序中使用V8——谷歌浏览器（Chrome）所使用的开源JavaScript引擎。 背景 这里的代码使用V8作为嵌入库来执行Jav...&nbsp;&nbsp;<a href='http://www.cppblog.com/woaidongmao/archive/2010/05/17/115578.html'>阅读全文</a><img src ="http://www.cppblog.com/woaidongmao/aggbug/115578.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/woaidongmao/" target="_blank">肥仔</a> 2010-05-17 12:25 <a href="http://www.cppblog.com/woaidongmao/archive/2010/05/17/115578.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>脚本引擎小PK: SpiderMonkey vs V8(二)</title><link>http://www.cppblog.com/woaidongmao/archive/2010/05/17/115577.html</link><dc:creator>肥仔</dc:creator><author>肥仔</author><pubDate>Mon, 17 May 2010 04:20:00 GMT</pubDate><guid>http://www.cppblog.com/woaidongmao/archive/2010/05/17/115577.html</guid><wfw:comment>http://www.cppblog.com/woaidongmao/comments/115577.html</wfw:comment><comments>http://www.cppblog.com/woaidongmao/archive/2010/05/17/115577.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/woaidongmao/comments/commentRss/115577.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/woaidongmao/services/trackbacks/115577.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 应用脚本引擎 要运行前文中的两段脚本代码，必须实现全局函数myprint和类MyClass，其中，MyClass有push()和pup()方法。 首先，我们来看看各自的框架代码 SpiderMonkey版 1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #def...&nbsp;&nbsp;<a href='http://www.cppblog.com/woaidongmao/archive/2010/05/17/115577.html'>阅读全文</a><img src ="http://www.cppblog.com/woaidongmao/aggbug/115577.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/woaidongmao/" target="_blank">肥仔</a> 2010-05-17 12:20 <a href="http://www.cppblog.com/woaidongmao/archive/2010/05/17/115577.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>脚本引擎小PK: SpiderMonkey vs V8(一)</title><link>http://www.cppblog.com/woaidongmao/archive/2010/05/17/115576.html</link><dc:creator>肥仔</dc:creator><author>肥仔</author><pubDate>Mon, 17 May 2010 04:15:00 GMT</pubDate><guid>http://www.cppblog.com/woaidongmao/archive/2010/05/17/115576.html</guid><wfw:comment>http://www.cppblog.com/woaidongmao/comments/115576.html</wfw:comment><comments>http://www.cppblog.com/woaidongmao/archive/2010/05/17/115576.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/woaidongmao/comments/commentRss/115576.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/woaidongmao/services/trackbacks/115576.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 介绍 SpiderMonkey是Firefox使用的脚本引擎，V8是Google Chrome使用的脚本引擎。这篇文章介绍了怎样在自己的C++程序中嵌入这两种脚本引擎，以及简单做了一些横向的对比。 编译 SpiderMonkey篇 SpiderMonkey支持1.0~1.8版本的JavaScript语法，包括ECMAScript，ECMA 263-3，以及Mozilla扩展，可选支持E4X 由于S...&nbsp;&nbsp;<a href='http://www.cppblog.com/woaidongmao/archive/2010/05/17/115576.html'>阅读全文</a><img src ="http://www.cppblog.com/woaidongmao/aggbug/115576.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/woaidongmao/" target="_blank">肥仔</a> 2010-05-17 12:15 <a href="http://www.cppblog.com/woaidongmao/archive/2010/05/17/115576.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>功能强大的JavaScript引擎--SpiderMonkey</title><link>http://www.cppblog.com/woaidongmao/archive/2010/05/17/115575.html</link><dc:creator>肥仔</dc:creator><author>肥仔</author><pubDate>Mon, 17 May 2010 04:13:00 GMT</pubDate><guid>http://www.cppblog.com/woaidongmao/archive/2010/05/17/115575.html</guid><wfw:comment>http://www.cppblog.com/woaidongmao/comments/115575.html</wfw:comment><comments>http://www.cppblog.com/woaidongmao/archive/2010/05/17/115575.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/woaidongmao/comments/commentRss/115575.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/woaidongmao/services/trackbacks/115575.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: JavaScript是由Netscape开发的对象脚本语言，其特点是开发简单、功能灵活，目前已广泛应用于WEB页面及服务器应用程序中。HTML本身是静态的、不允许用户干预，但用JavaScript编写的脚本程序就可以在用户的浏览器端运行，可以同用户进行交互，从而实现动态页面。可以将JavaScript与嵌入WEB的大多数对象的事件（如鼠标点击、移动等）相关联，然后用自己的方式处理这些事件。Java...&nbsp;&nbsp;<a href='http://www.cppblog.com/woaidongmao/archive/2010/05/17/115575.html'>阅读全文</a><img src ="http://www.cppblog.com/woaidongmao/aggbug/115575.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/woaidongmao/" target="_blank">肥仔</a> 2010-05-17 12:13 <a href="http://www.cppblog.com/woaidongmao/archive/2010/05/17/115575.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用 Lua 编写可嵌入式脚本</title><link>http://www.cppblog.com/woaidongmao/archive/2009/08/26/94449.html</link><dc:creator>肥仔</dc:creator><author>肥仔</author><pubDate>Wed, 26 Aug 2009 05:27:00 GMT</pubDate><guid>http://www.cppblog.com/woaidongmao/archive/2009/08/26/94449.html</guid><wfw:comment>http://www.cppblog.com/woaidongmao/comments/94449.html</wfw:comment><comments>http://www.cppblog.com/woaidongmao/archive/2009/08/26/94449.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/woaidongmao/comments/commentRss/94449.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/woaidongmao/services/trackbacks/94449.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 2006 年 6 月 12 日 虽然编译性编程语言和脚本语言各自具有自己独特的优点，但是如果我们使用这两种类型的语言来编写大型的应用程序会是什么样子呢？Lua 是一种嵌入式脚本语言，它非常小，速度很快，功能却非常强大。在创建其他配置文件或资源格式（以及与之对应的解析器）之前，请尝试一下 Lua。 尽管诸如 Perl、Python、PHP 和 Ruby 之类的解释性编程语言日益被 Web 应用程序广...&nbsp;&nbsp;<a href='http://www.cppblog.com/woaidongmao/archive/2009/08/26/94449.html'>阅读全文</a><img src ="http://www.cppblog.com/woaidongmao/aggbug/94449.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/woaidongmao/" target="_blank">肥仔</a> 2009-08-26 13:27 <a href="http://www.cppblog.com/woaidongmao/archive/2009/08/26/94449.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>