﻿<?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++博客-前进的路上-随笔分类-LUA</title><link>http://www.cppblog.com/wc250en007/category/14867.html</link><description>前进的路上</description><language>zh-cn</language><lastBuildDate>Fri, 16 Dec 2011 12:18:25 GMT</lastBuildDate><pubDate>Fri, 16 Dec 2011 12:18:25 GMT</pubDate><ttl>60</ttl><item><title>lua 中pairs 和 ipairs区别</title><link>http://www.cppblog.com/wc250en007/archive/2011/12/16/162203.html</link><dc:creator>Let me see see</dc:creator><author>Let me see see</author><pubDate>Fri, 16 Dec 2011 00:43:00 GMT</pubDate><guid>http://www.cppblog.com/wc250en007/archive/2011/12/16/162203.html</guid><wfw:comment>http://www.cppblog.com/wc250en007/comments/162203.html</wfw:comment><comments>http://www.cppblog.com/wc250en007/archive/2011/12/16/162203.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wc250en007/comments/commentRss/162203.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wc250en007/services/trackbacks/162203.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left"> 
<p><span style="font-family: 'book antiqua', palatino">标准库提供了集中迭代器，包括迭代文件每行的(io.lines)，迭代table元素的(pairs)，迭代数组元素的(ipairs)，迭代字符串中单词的</span>&nbsp;</p>
<p><span style="font-family: 'book antiqua', palatino">(string.gmatch)等等。LUA手册中对与pairs,ipairs解释如下：<br /></span></p></span></span><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left"> 
<h3 style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a style="color: rgb(51,102,153); text-decoration: none" name="pdf-ipairs"><code>ipairs (t)</code></a></h3>
<p>Returns three values: an iterator function, the table&nbsp;<code>t</code>, and 0, so that the construction</p><pre style="white-space: normal; word-wrap: break-word">for i,v in ipairs(t) do<span class="Apple-converted-space">&nbsp;</span><em>body</em><span class="Apple-converted-space">&nbsp;</span>end</pre>
<p>will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), &#183;&#183;&#183;, up to the first integer key absent from the table.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="word-spacing: normal">&nbsp;</p>
<p style="word-spacing: normal">&nbsp;</p>
<h3 style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a style="color: rgb(51,102,153); text-decoration: none" name="pdf-pairs"><code>pairs (t)</code></a></h3>
<p>Returns three values: the&nbsp;<a style="color: rgb(51,102,153); text-decoration: none" href="http://www.lua.org/manual/5.1/manual.html#pdf-next"><code>next</code></a>&nbsp;function, the table&nbsp;<code>t</code>, and&nbsp;<strong>nil</strong>, so that the construction</p><pre style="white-space: normal; word-wrap: break-word">for k,v in pairs(t) do<span class="Apple-converted-space">&nbsp;</span><em>body</em><span class="Apple-converted-space">&nbsp;</span>end</pre>
<p>will iterate over all key&#8211;value pairs of table&nbsp;<code>t</code>.</p>
<p style="word-spacing: normal">See function&nbsp;<a style="color: rgb(51,102,153); text-decoration: none" href="http://www.lua.org/manual/5.1/manual.html#pdf-next"><code>next</code></a>&nbsp;for the caveats of modifying the table during its traversal.</p>
<p style="word-spacing: normal">&nbsp;</p>
<p style="word-spacing: normal">这样就可以看出 &nbsp;ipairs以及pairs 的不同。</p>
<p style="word-spacing: normal">&nbsp;</p>
<p style="word-spacing: normal">pairs可以遍历表中所有的key，并且除了迭代器本身以及遍历表本身还可以返回nil;</p>
<p style="word-spacing: normal">&nbsp;</p>
<p style="word-spacing: normal">但是ipairs则不能返回nil,只能返回数字0，如果遇到nil则退出。它只能遍历到表中出现的第一个不是整数的key</p>
<p style="word-spacing: normal">&nbsp;</p></span></span><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left"> 
<p style="word-spacing: normal">下面举个例子吧！</p>
<p style="word-spacing: normal">&nbsp;</p>
<p style="word-spacing: normal">&nbsp;eg：</p>
<p style="word-spacing: normal"></p>
<p style="word-spacing: normal">local tabFiles = {</p>
<p style="word-spacing: normal">[3] = "test2",</p>
<p style="word-spacing: normal">[6] = "test3",</p>
<p style="word-spacing: normal">[4] = "test1"</p>
<p style="word-spacing: normal">}</p>
<p style="word-spacing: normal">&nbsp;</p>
<p style="word-spacing: normal">for k, v in ipairs(tabFiles) do</p>
<p style="word-spacing: normal">print(k, v)</p>
<p style="word-spacing: normal">end</p>
<p>&nbsp;</p>
<p style="word-spacing: normal">&nbsp;</p>
<p style="word-spacing: normal">猜测它的输出结果是什么呢？</p>
<p style="word-spacing: normal">&nbsp;</p>
<p style="word-spacing: normal">根据刚才的分析，它在&nbsp;ipairs(tabFiles) 遍历中，当key=1时候value就是nil，所以直接跳出循环不输出任何值。</p>
<p style="word-spacing: normal">&nbsp;</p>
<p style="word-spacing: normal"><span style="white-space: pre"></span><span>&gt;lua -e "io.stdout:setvbuf 'no'" "Test.lua"</span></p>
<p style="word-spacing: normal"><span style="white-space: pre"></span>&gt;Exit code: 0</p>
<p><span>&nbsp;</span></p>
<p><span>那么，如果是</span></p>
<p>for k, v in pairs(tabFiles) do</p>
<p>print(k, v)</p>
<p>end</p>
<div></div>
<div>则会输出所有 ：</div>
<div>
<div>&gt;lua -e "io.stdout:setvbuf 'no'" "Test.lua"&nbsp;</div>
<div>3 test2</div>
<div>6 test3</div>
<div>4 test1</div>
<div>&gt;Exit code: 0</div></div>
<div></div>
<div>现在改变一下表内容，</div>
<div>
<div>local tabFiles = {</div>
<div>[1] = "test1",</div>
<div>[6] = "test2",</div>
<div>[4] = "test3"</div>
<div>}</div>
<div></div>
<div>for k, v in ipairs(tabFiles) do</div>
<div>print(k, v)</div>
<div>end</div>
<div>现在的输出结果显而易见就是key=1时的value值test1</div>
<div></div></div>
<div>
<p style="word-spacing: normal">&nbsp;&gt;lua -e "io.stdout:setvbuf 'no'" "Test.lua"&nbsp;</p>
<p style="word-spacing: normal">1 test1</p>
<p style="word-spacing: normal">&gt;Exit code: 0&nbsp;</p>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #000000">--</span><span style="color: #000000">[示例1.]</span><span style="color: #000000">--</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />local&nbsp;tt&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000"><br /><img id="Codehighlighter1_22_71_Open_Image" onclick="this.style.display='none'; Codehighlighter1_22_71_Open_Text.style.display='none'; Codehighlighter1_22_71_Closed_Image.style.display='inline'; Codehighlighter1_22_71_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_22_71_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_22_71_Closed_Text.style.display='none'; Codehighlighter1_22_71_Open_Image.style.display='inline'; Codehighlighter1_22_71_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_22_71_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_22_71_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;[</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">test3</span><span style="color: #000000">"</span><span style="color: #000000">,<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;[</span><span style="color: #000000">4</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">test4</span><span style="color: #000000">"</span><span style="color: #000000">,<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;[</span><span style="color: #000000">5</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">test5</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;i,v&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;pairs(tt)&nbsp;</span><span style="color: #0000ff">do</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">--</span><span style="color: #000000">&nbsp;输出&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">test4</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">test3</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">test5</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;print(&nbsp;tt[i]&nbsp;)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />end<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;i,v&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;ipairs(tt)&nbsp;</span><span style="color: #0000ff">do</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">--</span><span style="color: #000000">&nbsp;输出&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">test3</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">2时断开<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;print(&nbsp;tt[i]&nbsp;)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />end<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #000000">--</span><span style="color: #000000">&nbsp;[[示例2.]]&nbsp;</span><span style="color: #000000">--</span><span style="color: #000000"><br /><img id="Codehighlighter1_242_288_Open_Image" onclick="this.style.display='none'; Codehighlighter1_242_288_Open_Text.style.display='none'; Codehighlighter1_242_288_Closed_Image.style.display='inline'; Codehighlighter1_242_288_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_242_288_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_242_288_Closed_Text.style.display='none'; Codehighlighter1_242_288_Open_Image.style.display='inline'; Codehighlighter1_242_288_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top">tbl&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span id="Codehighlighter1_242_288_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_242_288_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">"</span><span style="color: #000000">alpha</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">beta</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;[</span><span style="color: #000000">3</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">uno</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;[</span><span style="color: #000000">"</span><span style="color: #000000">two</span><span style="color: #000000">"</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">dos</span><span style="color: #000000">"</span><span style="color: #000000">}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;i,v&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;ipairs(tbl)&nbsp;</span><span style="color: #0000ff">do</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">--</span><span style="color: #000000">输出前三个<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;print(&nbsp;tbl[i]&nbsp;)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />end<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;i,v&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;pairs(tbl)&nbsp;</span><span style="color: #0000ff">do</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">--</span><span style="color: #000000">全部输出<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;print(&nbsp;tbl[i]&nbsp;)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />end</span></div>
<p style="word-spacing: normal"></p></div></span></span><br /><br /><br /><img src ="http://www.cppblog.com/wc250en007/aggbug/162203.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wc250en007/" target="_blank">Let me see see</a> 2011-12-16 08:43 <a href="http://www.cppblog.com/wc250en007/archive/2011/12/16/162203.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>lua5.1 编译+实例(转)</title><link>http://www.cppblog.com/wc250en007/archive/2011/06/28/149637.html</link><dc:creator>Let me see see</dc:creator><author>Let me see see</author><pubDate>Tue, 28 Jun 2011 02:06:00 GMT</pubDate><guid>http://www.cppblog.com/wc250en007/archive/2011/06/28/149637.html</guid><wfw:comment>http://www.cppblog.com/wc250en007/comments/149637.html</wfw:comment><comments>http://www.cppblog.com/wc250en007/archive/2011/06/28/149637.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wc250en007/comments/commentRss/149637.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wc250en007/services/trackbacks/149637.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="word-spacing: 0px; font: 12pt/25px Arial, Helvetica, simsun, u5b8bu4f53; text-transform: none; color: rgb(55,42,24); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(225,219,211); text-align: left; orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="word-spacing: 0px; font: 14px/21px verdana, sans-serif; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><font color="#ff0000">官方的Wiki:</font><a style="color: rgb(213,145,57); text-decoration: none" href="http://lua-users.org/wiki/TutorialExamples"><font color="#800080">http://lua-users.org/wiki/TutorialExamples</font></a></span><br />以下是关于vs2005中使用lua 
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp;以下是我在vs2005中编译方法：</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp;1:打开vs命令行工具、 &nbsp; 工具-&gt;visual studio 2005 command prompt</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp;2:到lua-5.1的目录也就是etc的上一级目录 &nbsp; &nbsp;：cd/d d:\lua-5.1</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp;3:执行：etc\luavs.bat(</span><font style="font-size: 26px; line-height: 41px" color="#ff0000"><span style="font-size: 12pt">注意：这里是\，不是/</span></font><span style="font-size: 12pt">)</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp;4:然后lua51.dll ，lua51.lib，lua.exe就生成在src路径下了~（注</span><font style="font-size: 26px; line-height: 41px" color="#ff0000"><span style="font-size: 12pt">意因为是lua5.1的所以没有luac.exe,以前的版本有</span></font><span style="font-size: 12pt">）</span></div>
<div style="font-size: 20px; line-height: 32px"><br style="font-size: 26px; line-height: 41px" /></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;&nbsp;因为在vs2005中lua是外来的，所以要让vs2005能找到lua的头文件和库文件（</span><font style="font-size: 26px; line-height: 41px" color="#ff0000"><span style="font-size: 12pt">lua5.1中只有一个lua51.lib</span></font><span style="font-size: 12pt">），在vs中包含</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">于是:工具-&gt;选项-&gt;项目和解决方案-&gt;vc++ 目录 &nbsp;右边选择包含文件把src的路径包含进来（关于头文件的）</span></div>
<div style="font-size: 20px; line-height: 32px">&nbsp;<font style="font-size: 26px; line-height: 41px" color="#ff0000"><span style="font-size: 12pt">还有库文件同意的操作，不过这里就是后来一直出错的点，这里这种方式包含的库文件是包含不进来的，后面讲到的一种方法可正确包含</span></font></div>
<div style="font-size: 20px; line-height: 32px"><font style="font-size: 26px; line-height: 41px" color="#ff0000"><br style="font-size: 34px; line-height: 54px" /></font></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp; 头文件和库文件都包含进来后就可以在c++中使用lua了</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">看一个实例如下：</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">#include &lt;stdio.h&gt;</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">#include &lt;iostream&gt;</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">extern "C"</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">{</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;&nbsp; #include "lua.h"</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;&nbsp; #include "lualib.h"</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;&nbsp; #include "lauxlib.h"</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">}//在工具中包含文件的那个~~</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">/* Lua解释器指针 */</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">lua_State * L;</span></div>
<div style="font-size: 20px; line-height: 32px"><font style="font-size: 26px; line-height: 41px" color="#ff0000"><span style="font-size: 12pt">#pragma comment(lib,"lua51.lib")//包含库文件~~在工具里包含不进来，上面的包含不进来的处理办法是：</span></font></div>
<div style="font-size: 20px; line-height: 32px"><font style="font-size: 26px; line-height: 41px" color="#ff0000"><span style="font-size: 12pt">//把lua51.dll 拷到项目的dubug目录下，把lua51.lib拷到项目目录的项目名的文件夹下</span></font></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">int main ()</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">{</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;/* 初始化Lua */</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;L = lua_open();</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;/* 载入Lua基本库 */</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;luaL_openlibs(L);</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;/* 运行脚本 ,注意路径*/</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;l</span><font style="font-size: 26px; line-height: 41px" color="#ff0000"><span style="font-size: 12pt">uaL_dofile(L, "d:\\test.lua");</span></font></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;/* 清除Lua */</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;lua_close(L);</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;//printf( "Press enter to exit&#8230;" );</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;//getchar();</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;return 0;</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">}</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">&nbsp;上面是c++的一个空工程</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">下面是test.lua的代码：是一个石头剪子布的小的游戏实例 &nbsp; &nbsp; &nbsp;</span></div>
<div style="font-size: 20px; line-height: 32px"><span style="font-size: 12pt">代码如下：</span></div>
<div style="font-size: 20px; line-height: 32px">
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">---[[</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">math.randomseed(os.time()) --[[为随机数产生器生成一个种子--]]</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">user_score = 0</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">comp_score = 0 &nbsp;-- 全局变量存分数</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">lookup = {}; &nbsp; &nbsp; --输赢对照表</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">lookup["rock"]={rock = "draw",paper = "lose",scissors ="win"}</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">lookup["paper"]={rock = "win",paper = "draw",scissors = "lose"}</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">lookup["scissors"]={rock = "lose",paper = "win",scissors = "draw"}</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">function GetAiMove() &nbsp;--Ai的函数</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;local int_to_string = {"rock","paper","scissors"} &nbsp;--局部一个table，对照用</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;return int_to_string[math.random(3)]</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">end</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">function EvaluateTheGuess(user_guess,comp_guess) &nbsp; -- 计算结果的函数</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;if(lookup[user_guess][comp_guess]=="win") then</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp; print ("user win the game")</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp; --print()</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp; user_score=user_score+1 &nbsp; &nbsp; &nbsp; &nbsp; --小错误 ~已改</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;elseif (lookup[user_guess][comp_guess]=="lose") then</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp; print ("user lose the game")</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp; --print()</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp; comp_score=comp_score+1</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;else</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp; &nbsp;print ("draw!")</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp; &nbsp;--print()</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;end</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">end</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">--下面开始</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">print ("game begin:enter q to guit game")</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">--print() --换行？</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">loop = true</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">while loop==true do</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;--print()</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;print("user: "..user_score.." comp: "..comp_score)</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;print()</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;print("p--布 &nbsp;r--拳头 &nbsp;s--减")</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;print("请输入：")</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;--io.open()</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;user_guess =io.stdin:read '*l' &nbsp; &nbsp;--出错的地方,这里是l不是1</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;--user_guess = "r"</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;print()</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;local letter_to_string = {r="rock",s="scissors",p="paper"} &nbsp; &nbsp;--亦是局部的一个table 对照用的</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;if(user_guess == "q") then</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp; loop = false</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;elseif(user_guess == "r") or (user_guess == "s") or(user_guess =="p") &nbsp;then</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp; comp_guess=GetAiMove()</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp; EvaluateTheGuess(letter_to_string[user_guess],comp_guess)</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;else</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp; &nbsp; print ("invalid input,try again")</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">&nbsp;&nbsp;end</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">end</span></div>
<div style="font-size: 26px; line-height: 41px"><span style="font-size: 12pt">--]]&nbsp;</span></div></div></span><br class="Apple-interchange-newline" /><img src ="http://www.cppblog.com/wc250en007/aggbug/149637.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wc250en007/" target="_blank">Let me see see</a> 2011-06-28 10:06 <a href="http://www.cppblog.com/wc250en007/archive/2011/06/28/149637.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>LUA脚本学习</title><link>http://www.cppblog.com/wc250en007/archive/2010/09/06/126030.html</link><dc:creator>Let me see see</dc:creator><author>Let me see see</author><pubDate>Mon, 06 Sep 2010 10:18:00 GMT</pubDate><guid>http://www.cppblog.com/wc250en007/archive/2010/09/06/126030.html</guid><wfw:comment>http://www.cppblog.com/wc250en007/comments/126030.html</wfw:comment><comments>http://www.cppblog.com/wc250en007/archive/2010/09/06/126030.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wc250en007/comments/commentRss/126030.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wc250en007/services/trackbacks/126030.html</trackback:ping><description><![CDATA[<p>从lua调用C++函数和对象<br>&nbsp;&nbsp;&nbsp; 利用LuaPlus可以方便的从C++中调用lua脚本，翻过也一样。通过注册函数或类对象，lua便可以访问C++。 <br>&nbsp;&nbsp;&nbsp; <br>一、C风格函数注册<br>&nbsp;&nbsp;&nbsp; Lua提供了C风格的回调函数注册，该函数原型如下：<br>&nbsp;&nbsp;&nbsp; int Callback(LuaState* state);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; 无论是全局函数、类非虚函数、类虚函数，只要符合上面的原型，都可以向Lua注册。我们以全局函数为例，下面是我们提供的一个回调函数CStyleAddFunc：</p>
<p>int CStyleAddFunc(LuaState * state) <br>{&nbsp;&nbsp;&nbsp; LuaStack args(state);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( args[1].IsNumber() &amp;&amp; args[2].IsNumber() )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; state-&gt;PushNumber(args[1].GetInteger() + args[2].GetInteger());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0; <br>}</p>
<p><br>&nbsp;&nbsp;&nbsp; 在回调函数中，我们通过栈来访问参数，栈中可以存贮多个参数，LuaStack args(state);语句获取栈对象供后续访问。&nbsp;&nbsp;&nbsp;&nbsp; 接下来判断参数是否是数字，如果两个参数都是数字，那么进行加操作，将结果压入栈中，将压入栈中的数据的个数返回。注意，返回值代表压入栈中的元素的个数，而不是某种计算结果或其它意义的返回值。通过改变返回值来查看程序的输出，这样可以对返回值的含义有个感性的了解。&nbsp;&nbsp;&nbsp;&nbsp; 要注册回到只需调用Register函数即可，这在第一篇中已经用到。下面是测试函数：</p>
<p>void TestCFunctionCallBack() <br>{<br>&nbsp;&nbsp; LuaStateOwner state;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //"print" need this<br>&nbsp;&nbsp; state-&gt;OpenLibs();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //register my function CStyleAddFunc to Add<br>&nbsp;&nbsp; state-&gt;GetGlobals().Register("Add", CStyleAddFunc);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //call my function and print the result&nbsp;&nbsp; <br>&nbsp;&nbsp; state-&gt;DoString("ret = Add(1,5);print(ret)"); <br>}</p>
<p>&nbsp;&nbsp; state-&gt;DoString("ret = Add(1,5); print(ret)");该句用来从执行Lua命令串。我们先调用Add并将结果赋值给ret变量，然后打印ret的值。 main函数如下： <br><br>int _tmain(int argc, _TCHAR* argv[]) <br>{&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; TestCFunctionCallBack();&nbsp;&nbsp; <br>&nbsp;&nbsp; return 0;<br>}</p>
<p>&nbsp;&nbsp; 编译运行，一切OK。&nbsp;&nbsp;&nbsp;&nbsp; 我们也可以从Lua脚本文件中调用注册的回调函数，第一篇中有演示。&nbsp;&nbsp;&nbsp;&nbsp; 要注册类的成员函数，则需要调用Register的另一种形式Register( const char* funcName, const Callee&amp; callee, int (Callee::*func)(LuaState*), int nupvalues = 0 );，提供类实例指针和函数即可完成注册。下面是示例代码：</p>
<p>class CTestCallBack <br>{ <br>public: <br>&nbsp;&nbsp; int NonVirtualFunc(LuaState *state)&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; {&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; LuaStack args(state);&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; printf("In non-virtual member function. no msg. ");&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; return 0;<br>&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;<br>&nbsp;&nbsp; int virtual VirtualFunc(LuaState *state)&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; LuaStack args(state);&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; printf("In virtual member function.msg=%s ", args[1].GetString());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; return 0;<br>&nbsp;&nbsp; }<br>}; <br><br>void TestClassMemberFuncReg() <br>{&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; LuaStateOwner state;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //"print" need this&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; state-&gt;OpenLibs();&nbsp;&nbsp; <br>&nbsp;&nbsp; LuaObject globalobj = state-&gt;GetGlobals(); <br>&nbsp;&nbsp; CTestCallBack tcb;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; globalobj.Register("MemberFunc", tcb, &amp;CTestCallBack::NonVirtualFunc);&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; state-&gt;DoString("MemberFunc()");&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; globalobj.Register("VirMemberFunc", tcb, &amp;CTestCallBack::VirtualFunc);&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; state-&gt;DoString("VirMemberFunc('Hi,myboy')"); <br>}</p>
<p><br>修改一下main函数，将TestClassMemberFuncReg()加进去就可以看效果了。</p>
<p>&nbsp;</p>
<p>二、任意形式C++函数注册<br>&nbsp;&nbsp;&nbsp; LuaPlus提供了 RegisterDirect() 来直接注册任意形式的函数，这样更为直接，不必受限于上述的函数原型，使用起来很方便。同样此函数像Register一样，可以注册类的成员函数（也需要显示指定this指针）。下面是代码:</p>
<p><br>float Add(float num1, float num2) <br>{&nbsp;&nbsp;&nbsp;&nbsp; <br>return num1 + num2; <br>} </p>
<p>class CForRegDirect<br>{ <br>public:<br>int Sum(int a, int b, int c)&nbsp;&nbsp;&nbsp; <br>{<br>&nbsp;&nbsp;&nbsp;&nbsp; return a+b+c;<br>}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //const is necessary<br>virtual void SeeMessage(const char *msg)&nbsp;&nbsp;&nbsp;&nbsp; <br>{<br>&nbsp;&nbsp;&nbsp;&nbsp; printf("msg=%s ", msg);<br>}<br>};</p>
<p>void TestRegisterDirect() <br>{<br>LuaStateOwner state;<br>state-&gt;OpenLibs();<br>LuaObject gobj = state-&gt;GetGlobals();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //register global function directly&nbsp;&nbsp;&nbsp;&nbsp; <br>gobj.RegisterDirect("Add", Add);&nbsp;&nbsp;&nbsp;&nbsp; <br>state-&gt;DoString("print(Add(1.5, 2.3))");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //register memberfunction&nbsp;&nbsp;&nbsp;&nbsp; <br>CForRegDirect forobj;&nbsp;&nbsp;&nbsp;&nbsp; <br>gobj.RegisterDirect("MemberSum", forobj, CForRegDirect::Sum);&nbsp;&nbsp;&nbsp;&nbsp; <br>state-&gt;DoString("print(MemberSum(1,2,7))");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>gobj.RegisterDirect("VirCMsg", forobj, CForRegDirect::SeeMessage);&nbsp;&nbsp;&nbsp;&nbsp; <br>state-&gt;DoString("print(VirCMsg('haha,Do you see me?'))");<br>}</p>
<p><br>三、注册函子对象<br>&nbsp;&nbsp;&nbsp; 上面两节的方式可以实现简单的回调注册，注册类的成员函数时需要显式提供类指针，不适合用于映射C++中的类结构。&nbsp;&nbsp;&nbsp;&nbsp; RegisterObjectFunctor()和元表（metatable）结合，提供了一种新的方法。我们不需要在注册函数时显式的提供this指针，作为替代，this指针可以从调用者的userdata或__object成员获取。&nbsp;&nbsp;&nbsp;&nbsp; 元表（metatable）是一个普通的表对象，它定义了一些可以被重写的操作，如add，sub，mul，index，call等，这些操作以"__"开头，如__add，__index等。加入你重写了__add，那么在执行add操作时就会调用你自己定义的__add操作。这种特性可以用来模拟C++中的类对象，注册函子对象正是利用了这种特性来实现的。&nbsp;&nbsp;&nbsp;&nbsp; 下面我们将一个C++类映射到Lua中。类代码如下：</p>
<p><br>class CMultiObject <br>{ <br>public:<br>&nbsp;&nbsp; CMultiObject(int num) :m_num(num)<br>&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;<br>&nbsp;&nbsp; int Print(LuaState* state)<br>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; printf("%d ", m_num);<br>&nbsp;&nbsp;&nbsp; return 0; <br>&nbsp;&nbsp; } <br>protected:&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; int m_num; <br><br>}; <br>void TestRegObjectDispatchFunctor()<br>{<br>&nbsp;&nbsp; LuaStateOwner state;<br>&nbsp;&nbsp; state-&gt;OpenLibs();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //create metaTable<br><br>&nbsp;&nbsp; LuaObject metaTableObj = state-&gt;GetGlobals().CreateTable("MultiObjectMetaTable"); <br>&nbsp;&nbsp; metaTableObj.SetObject("__index", metaTableObj);&nbsp;&nbsp;&nbsp;&nbsp; //register functor for multiobject <br>&nbsp;&nbsp; metaTableObj.RegisterObjectFunctor("Print", CMultiObject::Print);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //get a instances of CMultiObject<br><br>&nbsp;&nbsp; CMultiObject obj1(10);&nbsp;&nbsp;&nbsp;&nbsp; //"clone" a object in lua, the lua object(here is table) has obj1's data <br>&nbsp;&nbsp; LuaObject obj1Obj = state-&gt;BoxPointer(&amp;obj1);&nbsp;&nbsp;&nbsp;&nbsp; //set lua object's metatable to MetaTableObj&nbsp;&nbsp; <br>&nbsp;&nbsp; obj1Obj.SetMetaTable(metaTableObj);&nbsp;&nbsp;&nbsp;&nbsp; //put lua object to Global scope, thus it can be accessed later. <br>&nbsp;&nbsp; state-&gt;GetGlobals().SetObject("obj1", obj1Obj);&nbsp;&nbsp;&nbsp;<br><br>&nbsp;&nbsp; CMultiObject obj2(20); <br>&nbsp;&nbsp; LuaObject obj2Obj = state-&gt;BoxPointer(&amp;obj2);&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; obj2Obj.SetMetaTable(metaTableObj); <br>&nbsp;&nbsp; state-&gt;GetGlobals().SetObject("obj2", obj2Obj);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //now call Print and Print2&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; state-&gt;DoString("obj1:Print();"); <br>&nbsp;&nbsp; state-&gt;DoString("obj2:Print();");<br>}</p>
<p>&nbsp;&nbsp;&nbsp;<span style="COLOR: red"> 首先我们需要生成一个元表（metatable），将C++类的成员函数注册到该元表中。然后依据CMultiObject的实例生成lua中与其对应的对象（也是表），将该对象的metatable（也即该表的__object成员）设置为之前产生的元表。最后将新生成的lua对象放置到全局作用域中，这样后面就可以直接引用这些对象。&nbsp;&nbsp;&nbsp;&nbsp; 我们可以做这样的近似理解：每个实例的数据元素存放在与已对应的lua table中，而类的成员函数则存放在metatable中（函子对象）。当调用obj1obj:Print()时，会先找到其metatable，然后在metatable中找Print()函数。&nbsp;&nbsp;&nbsp;&nbsp; 这样便实现了类似C++中的类结构。每个实例有自己的数据，而所有实例共享一份方法列表。</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 另外一种方式是利用表的userdata来实现，需要先创建一个lua表对象，然后将C++对象obj1设置为该表的userdata（也是设置其__object成员），再将该表对象的metatable设置为我们之前创建的元表。最后就可以用表明来调用Print函数。代码如下：<br>&nbsp;&nbsp;&nbsp; <br>LuaObject table1Obj = state-&gt;GetGlobals().CreateTable("table1");<br>table1Obj.SetLightUserData("__object", &amp;obj1);&nbsp;&nbsp; <br>table1Obj.SetMetaTable(metaTableObj);&nbsp;&nbsp;&nbsp; <br>LuaObject table2Obj = state-&gt;GetGlobals().CreateTable("table2"); <br>table2Obj.SetLightUserData("__object", &amp;obj2);&nbsp;&nbsp; <br>table2Obj.SetMetaTable(metaTableObj);&nbsp;&nbsp; <br>state-&gt;DoString("table1:Print()"); <br>state-&gt;DoString("table2:Print()");</p>
<p>注册函子对象（RegisterObjectFunctor）这种方式的限制在于：要注册的函数必须符合原型（int Callback(LuaState* state);）。为了打破这种限制，LuaPlus提供了另外一种方式。<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>四、直接注册函子对象</p>
<p>&nbsp;&nbsp;&nbsp; 直接注册函子对象（RegisterObjectDirect）和RegisterDirect类似，不考虑函数原型，可以直接向元表注册任意形式的函数。&nbsp;&nbsp;&nbsp;&nbsp; 为CMultiObject添加新的成员函数：<br>&nbsp;&nbsp;&nbsp; <br>void Print2(int num)&nbsp;&nbsp; <br>{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; printf("%d %d\n", m_num, num);&nbsp;&nbsp; <br>}&nbsp;&nbsp; <br><br>调用RegisterObjectDirect方法： <br>metaTableObj.RegisterObjectDirect("Print2", (CMultiObject*)0, &amp;CMultiObject::Print2); <br><br>第二个参数(CMultiObject*)0有点奇怪，这是模板参数的需要。 <br>&nbsp;&nbsp;&nbsp; <br>最后：&nbsp;&nbsp; <br>state-&gt;DoString("obj1:Print2(5)");&nbsp;&nbsp;&nbsp; <br>state-&gt;DoString("obj2:Print2(15)");&nbsp;&nbsp; <br>state-&gt;DoString("table1:Print2(5)");&nbsp;&nbsp;&nbsp;&nbsp; <br>state-&gt;DoString("table2:Print2(15)");<br><br>五、注销回调</p>
<p>&nbsp;&nbsp;&nbsp; 注销回调是件简单的事情，调用SetNil("yourCallBack")即可，如： <br>gobj.SetNil("Add");<br>metaTableObj.SetNil("Print2"); <br><br>好了，迄今为止最长的一篇，看着像是LuaPlus文档的翻译（？），不过还是加入了一些自己的理解。文档我看了下，琢磨了半天才明白。希望能快点将LuaPlus用起来。 <br>资料：&nbsp;&nbsp;&nbsp;&nbsp; （1）Lua5.1参考手册&nbsp;&nbsp;&nbsp;&nbsp; （2）Lua入门wiki&nbsp;&nbsp;&nbsp;&nbsp; （3）LuaPlus.html，源码包中带的。<br><br>转载自<a href="http://hi.baidu.com/li9chuan/blog/item/e65e1d6dc0bd79f642169461.html">http://hi.baidu.com/li9chuan/blog/item/e65e1d6dc0bd79f642169461.html</a><br><br>参考：<a href="http://gpwiki.org/index.php/Scripting_with_LuaPlus_and_Cpp">http://gpwiki.org/index.php/Scripting_with_LuaPlus_and_Cpp</a>&nbsp; 简单的LUA脚本编写<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://wwhiz.com/LuaPlus/LuaPlus.html">http://wwhiz.com/LuaPlus/LuaPlus.html</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.cppblog.com/iwangchuchu/default.html?page=2">http://www.cppblog.com/iwangchuchu/default.html?page=2</a><br><br><br><br>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>引擎中的简单应用：<br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;CAICharacterCore::LoadLuaScript(&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;LuaFileName&nbsp;)<br><img id=Codehighlighter1_64_5060_Open_Image onclick="this.style.display='none'; Codehighlighter1_64_5060_Open_Text.style.display='none'; Codehighlighter1_64_5060_Closed_Image.style.display='inline'; Codehighlighter1_64_5060_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_64_5060_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_64_5060_Closed_Text.style.display='none'; Codehighlighter1_64_5060_Open_Image.style.display='inline'; Codehighlighter1_64_5060_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_64_5060_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_64_5060_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"><br><img id=Codehighlighter1_80_4789_Open_Image onclick="this.style.display='none'; Codehighlighter1_80_4789_Open_Text.style.display='none'; Codehighlighter1_80_4789_Closed_Image.style.display='inline'; Codehighlighter1_80_4789_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_80_4789_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_80_4789_Closed_Text.style.display='none'; Codehighlighter1_80_4789_Open_Image.style.display='inline'; Codehighlighter1_80_4789_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_80_4789_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_80_4789_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">LuaScript-&gt;GetGlobals().RegisterDirect(&nbsp;"Thinking",&nbsp;*this,&nbsp;&amp;CAICharacterCore::Thinking&nbsp;);</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_185_259_Open_Image onclick="this.style.display='none'; Codehighlighter1_185_259_Open_Text.style.display='none'; Codehighlighter1_185_259_Closed_Image.style.display='inline'; Codehighlighter1_185_259_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_185_259_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_185_259_Closed_Text.style.display='none'; Codehighlighter1_185_259_Open_Image.style.display='inline'; Codehighlighter1_185_259_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_185_259_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id=Codehighlighter1_185_259_Open_Text><span style="COLOR: #808080">////////////////////////////////////////////////////////////////////////</span><span style="COLOR: #008000">//</span><span style="COLOR: #808080"></span></span><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LuaObject&nbsp;metaTableObj&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;m_LuaScript</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetGlobals().CreateTable(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">MultiObjectMetaTable</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.SetObject(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">__index</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;metaTableObj);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">metaTableObj.RegisterObjectFunctor(&nbsp;"ClearMoveStep",&nbsp;&amp;CAICharacterCore::ClearMoveStep&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">metaTableObj.RegisterObjectFunctor(&nbsp;"RestoreHPInstant",&nbsp;&amp;CAICharacterCore::RestoreHPInstant&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">metaTableObj.RegisterObjectDirect(&nbsp;"SetSayTimeInterval",&nbsp;(CAICharacterCore*)0,&nbsp;&amp;CAICharacterCore::SetSayTimeInterval&nbsp;);</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">LoseHPInstant</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::LoseHPInstant&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">LoseMPInstant</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::LoseMPInstant&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">RestoreHPInstant</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::RestoreHPInstant&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">RestoreMPInstant</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::RestoreMPInstant&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetHP</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetHP&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetMP</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetMP&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetHPMax</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetHPMax&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetMPMax</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetMPMax&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">UseSkill</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::UseSkill&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Say</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::Say&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">SayAdvance</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::SayAdvance&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetRand</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetRand&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetLevel</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetLevel&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">DropItemRand</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::DropItemRand&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">AddTimer</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::AddTimer&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetTimer</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetTimer&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetTargetHP</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetTargetHP&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetTargetMP</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetTargetMP&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetTargetHPMax</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetTargetHPMax&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetTargetMPMax</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetTargetMPMax&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetTargetLevel</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetTargetLevel&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetTargetEnmity</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetTargetEnmity&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">SetTargetEnmity</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::SetTargetEnmity&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetTargetDistance</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetTargetDistance&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">SetArray</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::SetArray&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetArray</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetArray&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">SetBoolArray</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::SetBoolArray&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">GetBoolArray</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::GetBoolArray&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;metaTableObj.RegisterObjectDirect(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">SelfMurder</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(CAICharacterCore</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CAICharacterCore::SelfMurder&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">metaTableObj.RegisterObjectDirect(&nbsp;"GetTargetName",&nbsp;(CAICharacterCore*)0,&nbsp;&amp;CAICharacterCore::GetTargetName&nbsp;);</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LuaObject&nbsp;CAICharacterCoreObj&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;m_LuaScript</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">BoxPointer(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CAICharacterCoreObj.SetMetaTable(metaTableObj);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_LuaScript</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetGlobals().SetObject(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">AI</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;CAICharacterCoreObj&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(&nbsp;</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">m_LuaScript</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">LoadFile(&nbsp;LuaFileName&nbsp;)&nbsp;)<br><img id=Codehighlighter1_4310_4383_Open_Image onclick="this.style.display='none'; Codehighlighter1_4310_4383_Open_Text.style.display='none'; Codehighlighter1_4310_4383_Closed_Image.style.display='inline'; Codehighlighter1_4310_4383_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_4310_4383_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_4310_4383_Closed_Text.style.display='none'; Codehighlighter1_4310_4383_Open_Image.style.display='inline'; Codehighlighter1_4310_4383_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_4310_4383_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_4310_4383_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_bLuaScriptLoaded&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_LuaScript</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Call(&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">LuaStateOwner&nbsp;LuaScript;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">LuaScript-&gt;LoadFile(&nbsp;"D:/ArenWorkstation/XSanguoRun/Server/Script/AI/test.lua"&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">LuaObject&nbsp;luaFun&nbsp;=&nbsp;LuaScript-&gt;GetGlobal(&nbsp;"Event_OnInit"&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">if(&nbsp;luaFun.IsFunction()&nbsp;)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;int&nbsp;y&nbsp;=&nbsp;0;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">m_LuaScript-&gt;DoString("print(obj1:ClearMoveStep())");<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">LuaScript-&gt;LoadFile(&nbsp;"D:/ArenWorkstation/XSanguoRun/Server/test.lua"&nbsp;);</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000">&nbsp;(LuaPlus::LuaException&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">e)<br><img id=Codehighlighter1_4832_5057_Open_Image onclick="this.style.display='none'; Codehighlighter1_4832_5057_Open_Text.style.display='none'; Codehighlighter1_4832_5057_Closed_Image.style.display='inline'; Codehighlighter1_4832_5057_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_4832_5057_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_4832_5057_Closed_Text.style.display='none'; Codehighlighter1_4832_5057_Open_Image.style.display='inline'; Codehighlighter1_4832_5057_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_4832_5057_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_4832_5057_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_4861_4863_Open_Image onclick="this.style.display='none'; Codehighlighter1_4861_4863_Open_Text.style.display='none'; Codehighlighter1_4861_4863_Closed_Image.style.display='inline'; Codehighlighter1_4861_4863_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_4861_4863_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_4861_4863_Closed_Text.style.display='none'; Codehighlighter1_4861_4863_Open_Image.style.display='inline'; Codehighlighter1_4861_4863_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;szErr[</span><span style="COLOR: #000000">1024</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span id=Codehighlighter1_4861_4863_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_4861_4863_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_snprintf(szErr,&nbsp;</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(szErr)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">怪物&nbsp;%s&nbsp;AI脚本载入错误：&nbsp;%s</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;m_data.szCharacterName,&nbsp;e.GetErrorMessage());<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetErrorLog()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">logString(szErr);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_bLuaScriptLoaded&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<img src ="http://www.cppblog.com/wc250en007/aggbug/126030.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wc250en007/" target="_blank">Let me see see</a> 2010-09-06 18:18 <a href="http://www.cppblog.com/wc250en007/archive/2010/09/06/126030.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>