﻿<?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++博客-前进的路上-随笔分类-LuaPlus</title><link>http://www.cppblog.com/wc250en007/category/17338.html</link><description>前进的路上</description><language>zh-cn</language><lastBuildDate>Mon, 18 Jul 2011 14:00:33 GMT</lastBuildDate><pubDate>Mon, 18 Jul 2011 14:00:33 GMT</pubDate><ttl>60</ttl><item><title>luaplus脚本中使用成员函数</title><link>http://www.cppblog.com/wc250en007/archive/2011/07/18/151300.html</link><dc:creator>Let me see see</dc:creator><author>Let me see see</author><pubDate>Mon, 18 Jul 2011 05:27:00 GMT</pubDate><guid>http://www.cppblog.com/wc250en007/archive/2011/07/18/151300.html</guid><wfw:comment>http://www.cppblog.com/wc250en007/comments/151300.html</wfw:comment><comments>http://www.cppblog.com/wc250en007/archive/2011/07/18/151300.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wc250en007/comments/commentRss/151300.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wc250en007/services/trackbacks/151300.html</trackback:ping><description><![CDATA[<div>在脚本中使用类的成员函数 
<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">#include&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">luaplus.h</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;LuaPlus;<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="" />template</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;T&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;LuaExport<br /><img id="Codehighlighter1_83_1148_Open_Image" onclick="this.style.display='none'; Codehighlighter1_83_1148_Open_Text.style.display='none'; Codehighlighter1_83_1148_Closed_Image.style.display='inline'; Codehighlighter1_83_1148_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_83_1148_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_83_1148_Closed_Text.style.display='none'; Codehighlighter1_83_1148_Open_Image.style.display='inline'; Codehighlighter1_83_1148_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_83_1148_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_83_1148_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;LuaExport(</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;pszName,&nbsp;LuaPlus::LuaState</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pState&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img id="Codehighlighter1_157_598_Open_Image" onclick="this.style.display='none'; Codehighlighter1_157_598_Open_Text.style.display='none'; Codehighlighter1_157_598_Closed_Image.style.display='inline'; Codehighlighter1_157_598_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_157_598_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_157_598_Closed_Text.style.display='none'; Codehighlighter1_157_598_Open_Image.style.display='inline'; Codehighlighter1_157_598_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_157_598_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_157_598_Open_Text"><span style="color: #000000">{&nbsp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">TDAssert(s_pMe&nbsp;==&nbsp;0);</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s_pMe&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;static_cast</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;T</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">(</span><span style="color: #0000ff">this</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LuaPlus::LuaState</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;theState&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pState;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">?&nbsp;pState&nbsp;:&nbsp;CScriptSystem::_GetLuaState();</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s_pMetaTable&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;LuaPlus::LuaObject;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">s_pMetaTable&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;theState</span><span style="color: #000000">-&gt;</span><span style="color: #000000">GetGlobals().CreateTable(pszName);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s_pMetaTable</span><span style="color: #000000">-&gt;</span><span style="color: #000000">SetObject(</span><span style="color: #000000">"</span><span style="color: #000000">__index</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">s_pMetaTable);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LuaObject&nbsp;obj&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;theState</span><span style="color: #000000">-&gt;</span><span style="color: #000000">BoxPointer(s_pMe);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;obj.SetMetaTable(</span><span style="color: #000000">*</span><span style="color: #000000">s_pMetaTable);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;theState</span><span style="color: #000000">-&gt;</span><span style="color: #000000">GetGlobals().SetObject(pszName,&nbsp;obj);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">virtual</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">~</span><span style="color: #000000">LuaExport()<br /><img id="Codehighlighter1_624_681_Open_Image" onclick="this.style.display='none'; Codehighlighter1_624_681_Open_Text.style.display='none'; Codehighlighter1_624_681_Closed_Image.style.display='inline'; Codehighlighter1_624_681_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_624_681_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_624_681_Closed_Text.style.display='none'; Codehighlighter1_624_681_Open_Image.style.display='inline'; Codehighlighter1_624_681_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_624_681_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_624_681_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delete&nbsp;s_pMetaTable;&nbsp;s_pMetaTable&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s_pMe&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;template&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;Callee</span><span style="color: #000000">&gt;</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: #0000ff">void</span><span style="color: #000000">&nbsp;RegisterFunction(</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;pszFuncName,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;(Callee::</span><span style="color: #000000">*</span><span style="color: #000000">func)(LuaPlus::LuaState</span><span style="color: #000000">*</span><span style="color: #000000">))<br /><img id="Codehighlighter1_799_860_Open_Image" onclick="this.style.display='none'; Codehighlighter1_799_860_Open_Text.style.display='none'; Codehighlighter1_799_860_Closed_Image.style.display='inline'; Codehighlighter1_799_860_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_799_860_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_799_860_Closed_Text.style.display='none'; Codehighlighter1_799_860_Open_Image.style.display='inline'; Codehighlighter1_799_860_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_799_860_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_799_860_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s_pMetaTable</span><span style="color: #000000">-&gt;</span><span style="color: #000000">RegisterObjectFunctor(pszFuncName,&nbsp;func);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">取得自己</span><span style="color: #008000"><br /><img id="Codehighlighter1_895_911_Open_Image" onclick="this.style.display='none'; Codehighlighter1_895_911_Open_Text.style.display='none'; Codehighlighter1_895_911_Closed_Image.style.display='inline'; Codehighlighter1_895_911_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_895_911_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_895_911_Closed_Text.style.display='none'; Codehighlighter1_895_911_Open_Image.style.display='inline'; Codehighlighter1_895_911_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;T</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;GetMe(</span><span style="color: #0000ff">void</span><span style="color: #000000">)&nbsp;&nbsp;</span><span id="Codehighlighter1_895_911_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_895_911_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;s_pMe;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">protected</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: #0000ff">static</span><span style="color: #000000">&nbsp;T</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s_pMe;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">自身实例，全局变量</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;LuaPlus::LuaObject</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;s_pMetaTable;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">MetaTable</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">private</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: #008000">//</span><span style="color: #008000">&nbsp;unimplemented&nbsp;constructors&nbsp;/&nbsp;assignment</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;LuaExport(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;LuaExport</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;obj);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;LuaExport</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">operator</span><span style="color: #000000">=</span><span style="color: #000000">(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;LuaExport</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;obj);<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">extern</span><span style="color: #000000">&nbsp;LuaPlus::LuaState</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;GetLuaState();</span></div><br />// 测试main.cpp<br /><br />
<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: #0000ff">class</span><span style="color: #000000">&nbsp;player&nbsp;:&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;LuaExport</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;player&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img id="Codehighlighter1_42_652_Open_Image" onclick="this.style.display='none'; Codehighlighter1_42_652_Open_Text.style.display='none'; Codehighlighter1_42_652_Closed_Image.style.display='inline'; Codehighlighter1_42_652_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_42_652_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_42_652_Closed_Text.style.display='none'; Codehighlighter1_42_652_Open_Image.style.display='inline'; Codehighlighter1_42_652_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_42_652_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_42_652_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;player():<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LuaExport</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;player&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">(&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">pp</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;GetLuaState()&nbsp;)<br /><img id="Codehighlighter1_112_118_Open_Image" onclick="this.style.display='none'; Codehighlighter1_112_118_Open_Text.style.display='none'; Codehighlighter1_112_118_Closed_Image.style.display='inline'; Codehighlighter1_112_118_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_112_118_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_112_118_Closed_Text.style.display='none'; Codehighlighter1_112_118_Open_Image.style.display='inline'; Codehighlighter1_112_118_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_112_118_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_112_118_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;LS_PrintNumber(LuaState</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;state)<br /><img id="Codehighlighter1_163_379_Open_Image" onclick="this.style.display='none'; Codehighlighter1_163_379_Open_Text.style.display='none'; Codehighlighter1_163_379_Closed_Image.style.display='inline'; Codehighlighter1_163_379_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_163_379_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_163_379_Closed_Text.style.display='none'; Codehighlighter1_163_379_Open_Image.style.display='inline'; Codehighlighter1_163_379_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_163_379_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_163_379_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LuaStack&nbsp;args(state);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img id="Codehighlighter1_220_269_Open_Image" onclick="this.style.display='none'; Codehighlighter1_220_269_Open_Text.style.display='none'; Codehighlighter1_220_269_Closed_Image.style.display='inline'; Codehighlighter1_220_269_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_220_269_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_220_269_Closed_Text.style.display='none'; Codehighlighter1_220_269_Open_Image.style.display='inline'; Codehighlighter1_220_269_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(args[</span><span style="color: #000000">2</span><span style="color: #000000">].IsNumber())&nbsp;</span><span id="Codehighlighter1_220_269_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_220_269_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%f\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;args[</span><span style="color: #000000">2</span><span style="color: #000000">].GetNumber());<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp;args[</span><span style="color: #000000">2</span><span style="color: #000000">].IsString()&nbsp;)<br /><img id="Codehighlighter1_310_360_Open_Image" onclick="this.style.display='none'; Codehighlighter1_310_360_Open_Text.style.display='none'; Codehighlighter1_310_360_Closed_Image.style.display='inline'; Codehighlighter1_310_360_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_310_360_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_310_360_Closed_Text.style.display='none'; Codehighlighter1_310_360_Open_Image.style.display='inline'; Codehighlighter1_310_360_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_310_360_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_310_360_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%s\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;args[</span><span style="color: #000000">2</span><span style="color: #000000">].GetString()&nbsp;);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;UI_SetTipText(&nbsp;lua_State&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">state&nbsp;)<br /><img id="Codehighlighter1_425_649_Open_Image" onclick="this.style.display='none'; Codehighlighter1_425_649_Open_Text.style.display='none'; Codehighlighter1_425_649_Closed_Image.style.display='inline'; Codehighlighter1_425_649_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_425_649_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_425_649_Closed_Text.style.display='none'; Codehighlighter1_425_649_Open_Image.style.display='inline'; Codehighlighter1_425_649_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_425_649_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_425_649_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LuaStack&nbsp;args(state);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp;args[</span><span style="color: #000000">2</span><span style="color: #000000">].IsString()&nbsp;)<br /><img id="Codehighlighter1_487_629_Open_Image" onclick="this.style.display='none'; Codehighlighter1_487_629_Open_Text.style.display='none'; Codehighlighter1_487_629_Closed_Image.style.display='inline'; Codehighlighter1_487_629_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_487_629_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_487_629_Closed_Text.style.display='none'; Codehighlighter1_487_629_Open_Image.style.display='inline'; Codehighlighter1_487_629_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_487_629_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_487_629_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">szData&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;args[</span><span style="color: #000000">2</span><span style="color: #000000">].GetString();</span><span style="color: #008000">//</span><span style="color: #008000">lua_tostring(state,&nbsp;1);</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;szData&nbsp;)<br /><img id="Codehighlighter1_584_623_Open_Image" onclick="this.style.display='none'; Codehighlighter1_584_623_Open_Text.style.display='none'; Codehighlighter1_584_623_Closed_Image.style.display='inline'; Codehighlighter1_584_623_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_584_623_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_584_623_Closed_Text.style.display='none'; Codehighlighter1_584_623_Open_Image.style.display='inline'; Codehighlighter1_584_623_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_584_623_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_584_623_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%s\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;szData&nbsp;);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><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="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />player</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;LuaExport</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;player&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">::s_pMe&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />LuaPlus::LuaObject</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;LuaExport</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;player&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">::s_pMetaTable&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</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">int</span><span style="color: #000000">&nbsp;_tmain(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;argc,&nbsp;_TCHAR</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;argv[])<br /><img id="Codehighlighter1_794_1147_Open_Image" onclick="this.style.display='none'; Codehighlighter1_794_1147_Open_Text.style.display='none'; Codehighlighter1_794_1147_Closed_Image.style.display='inline'; Codehighlighter1_794_1147_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_794_1147_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_794_1147_Closed_Text.style.display='none'; Codehighlighter1_794_1147_Open_Image.style.display='inline'; Codehighlighter1_794_1147_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_794_1147_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_794_1147_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;player</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pPlayer&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;player();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pPlayer</span><span style="color: #000000">-&gt;</span><span style="color: #000000">RegisterFunction(&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">PrintNumber</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">player::LS_PrintNumber&nbsp;);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pPlayer</span><span style="color: #000000">-&gt;</span><span style="color: #000000">RegisterFunction(&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">SetTips</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">player::LS_PrintNumber&nbsp;);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;Register&nbsp;your&nbsp;functions.</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></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: #0000ff">int</span><span style="color: #000000">&nbsp;nRet&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;GetLuaState()</span><span style="color: #000000">-&gt;</span><span style="color: #000000">DoFile(&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">main.lua</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp; nRet&nbsp;)<br /><img id="Codehighlighter1_1058_1122_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1058_1122_Open_Text.style.display='none'; Codehighlighter1_1058_1122_Closed_Image.style.display='inline'; Codehighlighter1_1058_1122_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1058_1122_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1058_1122_Closed_Text.style.display='none'; Codehighlighter1_1058_1122_Open_Image.style.display='inline'; Codehighlighter1_1058_1122_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_1058_1122_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_1058_1122_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">错误信息:&nbsp;%s</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;GetLuaState()</span><span style="color: #000000">-&gt;</span><span style="color: #000000">StackTop().GetString());<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;getchar();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div><br />// main.lua<br />&nbsp;&nbsp;&nbsp;
<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">pp.PrintNumber(</span><span style="color: #000000">1000</span><span style="color: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span></div><br /><br />1.需要注意的是，类的成员函数中的参数&nbsp; 默认第一个为this<br />所以 要活得参数的时候 下标默认加1<br />&nbsp;if (args[2].IsNumber()) <br />{<br />&nbsp;&nbsp;&nbsp;&nbsp; printf("%f\n", args[2].GetNumber());<br />&nbsp;}<br /><br /><br /><br /></div><img src ="http://www.cppblog.com/wc250en007/aggbug/151300.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-07-18 13:27 <a href="http://www.cppblog.com/wc250en007/archive/2011/07/18/151300.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>luaplus上手 (转)</title><link>http://www.cppblog.com/wc250en007/archive/2011/07/18/151284.html</link><dc:creator>Let me see see</dc:creator><author>Let me see see</author><pubDate>Mon, 18 Jul 2011 02:10:00 GMT</pubDate><guid>http://www.cppblog.com/wc250en007/archive/2011/07/18/151284.html</guid><wfw:comment>http://www.cppblog.com/wc250en007/comments/151284.html</wfw:comment><comments>http://www.cppblog.com/wc250en007/archive/2011/07/18/151284.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wc250en007/comments/commentRss/151284.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wc250en007/services/trackbacks/151284.html</trackback:ping><description><![CDATA[<span style="word-spacing: 0px; font: 14px/21px Verdana, Geneva, Arial, Helvetica, sans-serif; text-transform: none; color: rgb(75,75,75); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"> 
<p><span style="font-size: 9pt; font-family: 宋体">版权所有,转载请注明出处,勿用于商业用途,谢谢!</span></p>
<p><span style="font-size: 9pt; font-family: 宋体">作者:<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>大宝天天见</span></p>
<p><span style="font-size: 9pt; font-family: 宋体">Blog:&nbsp;&nbsp;&nbsp;&nbsp;<a style="color: rgb(26,139,200); text-decoration: none" href="http://www.cppblog.com/singohgod"><u>http://www.cppblog.com/singohgod</u></a></span></p>
<p><span style="font-size: 9pt; font-family: 宋体">本人水平有限,有错请指出,欢迎交流,共同进步!<br /><br /></span></p>
<p><span style="font-family: 宋体"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="120" src="http://www.cppblog.com/images/cppblog_com/singohgod/4054/t_Lua_LOGO.jpg" width="119" border="0"  alt="" />&nbsp;<img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="120" src="http://www.cppblog.com/images/cppblog_com/singohgod/4054/t_LuaPlus_LOGO.jpg" width="120" border="0"  alt="" /><br /></span></p>
<p>&nbsp;</p>
<p style="text-indent: 21.75pt"><span style="font-family: 宋体">国内关于</span>Lua<span style="font-family: 宋体">的资料实在是太少</span>,<span style="font-family: 宋体">为了寻找一个合适的</span>Lua<span style="font-family: 宋体">的</span>C++<span style="font-family: 宋体">封装</span>,<span style="font-family: 宋体">真是如同大海捞针</span>.<span style="font-family: 宋体">在看了众多资料后锁定以下几种</span>:LuaBind ToLua++ LuaPlus.<span style="font-family: 宋体">在选择上颇有讽刺的味道</span>,LuaBind<span style="font-family: 宋体">的版本号还没到</span>1.0,<span style="font-family: 宋体">加上网友颇有微词</span>,<span style="font-family: 宋体">放弃</span>.ToLua++<span style="font-family: 宋体">本来有朋友推荐</span>,<span style="font-family: 宋体">但是怎么都找不到下载</span>,<span style="font-family: 宋体">官网就是打不开</span>,<span style="font-family: 宋体">无赖放弃</span>.<span style="font-family: 宋体">就只有</span>LuaPlus<span style="font-family: 宋体">了</span>,<span style="font-family: 宋体">看到一些人的评价还行</span>,<span style="font-family: 宋体">于是决定就用它吧</span>.</p>
<p style="text-indent: 21.75pt">LuaPlus<span style="font-family: 宋体">的资料就更少了</span>,<span style="font-family: 宋体">连怎么配置怎么调试等什么都没有</span>,<span style="font-family: 宋体">只有沐枫大哥讲解了语法方面的一篇文章</span>.<span style="font-family: 宋体">啊哟</span>,<span style="font-family: 宋体">怎么搞呢</span>,<span style="font-family: 宋体">难道又只有硬着头皮上了</span>?(<span style="font-family: 宋体">某伟人曾说过</span>,<span style="font-family: 宋体">但凡杰出的事都是硬着头皮干出来滴</span>)</p>
<p style="text-indent: 21.75pt"><span style="font-family: 宋体">好了</span>,<span style="font-family: 宋体">言归正传</span>,<span style="font-family: 宋体">下面讲讲我的经验吧</span>:</p>
<p>&nbsp;</p>
<p><strong><span style="font-size: 14pt; color: red; font-family: 宋体">如何编译</span></strong><strong></strong></p>
<p style="margin: 0cm 0cm 0pt 18pt; text-indent: -18pt"><strong><span style="color: maroon">1.<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></strong><strong><span style="color: maroon; font-family: 宋体">下载</span></strong></p>
<p><span style="font-family: 宋体">首先到官方网站下载</span>:&nbsp;<a style="color: rgb(26,139,200); text-decoration: none" href="http://www.luaplus.org/"><u>http://www.luaplus.org/</u></a></p>
<p><span style="font-family: 宋体">下载这个</span>: All source code:&nbsp;<a style="color: rgb(26,139,200); text-decoration: none" href="http://luaplus.org/LuaPlus51_Build1100.zip"><u>http://luaplus.org/LuaPlus51_Build1100.zip</u></a>&nbsp;(<span style="font-family: 宋体">我当前的版本</span>,<span style="font-family: 宋体">当然越新越好</span>)</p>
<p>&nbsp;</p>
<p style="margin: 0cm 0cm 0pt 18pt; text-indent: -18pt"><strong><span style="color: maroon">2.<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></strong><strong><span style="color: maroon; font-family: 宋体">剥离</span></strong></p>
<p><span style="font-family: 宋体">解开下载包</span>,<span style="font-family: 宋体">打开</span>&nbsp;\LuaPlus51_Build1100\Src\LuaPlus&nbsp;<span style="font-family: 宋体">里面是全部源文件</span>,src<span style="font-family: 宋体">下是</span>lua<span style="font-family: 宋体">的源文件</span>.<span style="font-family: 宋体">这里有个令人疑惑的地方</span>,<span style="font-family: 宋体">源文件中带了一些不需要的文件</span>,<span style="font-family: 宋体">要剔除去</span>,<span style="font-family: 宋体">基本上需要以下这些文件</span>:</p>
<p style="margin: 0cm 0cm 0pt 39pt; text-indent: -18pt"><span>1)<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>Lua<span style="font-family: 宋体">库文件</span>:</p>
<p>
<table style="border-right: medium none; border-top: medium none; border-left: medium none; border-bottom: medium none; border-collapse: collapse" cellspacing="0" cellpadding="0" border="1">
<tbody>
<tr>
<td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; font-size: 12px; padding-bottom: 0cm; border-left: windowtext 1pt solid; width: 142pt; color: rgb(69,69,69); line-height: 16px; padding-top: 0cm; border-bottom: windowtext 1pt solid; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: transparent; word-wrap: break-word" valign="top" width="189">
<p style="margin: 0cm 0cm 0pt 21pt">lapi.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lapi.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">lauxlib.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lauxlib.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">lbaselib.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lcode.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lcode.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">ldblib.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">ldebug.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">ldebug.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">ldo.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">ldo.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">ldump.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lfunc.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lfunc.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">lgc.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lgc.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">linit.c</p></td>
<td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; font-size: 12px; border-left-color: rgb(236,233,216); padding-bottom: 0cm; width: 142.05pt; color: rgb(69,69,69); line-height: 16px; padding-top: 0cm; border-bottom: windowtext 1pt solid; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: transparent; word-wrap: break-word" valign="top" width="189">
<p style="margin: 0cm 0cm 0pt 21pt">liolib.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">llex.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">llex.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">llimits.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">lmathlib.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lmem.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lmem.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">loadlib.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lobject.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lobject.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">lopcodes.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lopcodes.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">loslib.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lparser.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lparser.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">lstate.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lstate.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">lstring.c</p></td>
<td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; font-size: 12px; border-left-color: rgb(236,233,216); padding-bottom: 0cm; width: 142.05pt; color: rgb(69,69,69); line-height: 16px; padding-top: 0cm; border-bottom: windowtext 1pt solid; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: transparent; word-wrap: break-word" valign="top" width="189">
<p style="margin: 0cm 0cm 0pt 21pt">lstring.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">lstrlib.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">ltable.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">ltable.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">ltablib.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">ltm.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">ltm.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">lua.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">luaconf.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">lualib.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">lundump.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lundump.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">lvm.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lvm.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">lzio.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">lzio.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">print.c</p></td></tr></tbody></table></p>
<p style="margin: 0cm 0cm 0pt 21pt">&nbsp;</p>
<p style="margin: 0cm 0cm 0pt 39pt; text-indent: -18pt"><span>2)<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>LuaPlus<span style="font-family: 宋体">头文件</span>:</p>
<p>
<table style="border-right: medium none; border-top: medium none; border-left: medium none; border-bottom: medium none; border-collapse: collapse" cellspacing="0" cellpadding="0" border="1">
<tbody>
<tr>
<td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; font-size: 12px; padding-bottom: 0cm; border-left: windowtext 1pt solid; width: 213.05pt; color: rgb(69,69,69); line-height: 16px; padding-top: 0cm; border-bottom: windowtext 1pt solid; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: transparent; word-wrap: break-word" valign="top" width="284">
<p style="margin: 0cm 0cm 0pt 21pt">auxiliar.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaAutoBlock.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaCall.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaFunction.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaHelper.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaHelper_Object.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaHelper_StackObject.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaLink.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaObject.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaObject.inl</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaPlus.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaPlusCD.h</p></td>
<td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; font-size: 12px; border-left-color: rgb(236,233,216); padding-bottom: 0cm; width: 213.05pt; color: rgb(69,69,69); line-height: 16px; padding-top: 0cm; border-bottom: windowtext 1pt solid; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: transparent; word-wrap: break-word" valign="top" width="284">
<p style="margin: 0cm 0cm 0pt 21pt">LuaPlusFunctions.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaPlusInternal.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaStackObject.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaStackObject.inl</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaStackTableIterator.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaState.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaState.inl</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaStateOutFile.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaTableIterator.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">luathread.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">pt.h</p>
<p style="margin: 0cm 0cm 0pt 21pt">srm.h</p></td></tr></tbody></table></p>
<p style="margin: 0cm 0cm 0pt 21pt">&nbsp;</p>
<p style="margin: 0cm 0cm 0pt 39pt; text-indent: -18pt"><span>3)<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>LuaPlus<span style="font-family: 宋体">源文件</span></p>
<p>
<table style="border-right: medium none; border-top: medium none; border-left: medium none; border-bottom: medium none; border-collapse: collapse" cellspacing="0" cellpadding="0" border="1">
<tbody>
<tr>
<td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; font-size: 12px; padding-bottom: 0cm; border-left: windowtext 1pt solid; width: 213.05pt; color: rgb(69,69,69); line-height: 16px; padding-top: 0cm; border-bottom: windowtext 1pt solid; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: transparent; word-wrap: break-word" valign="top" width="284">
<p style="margin: 0cm 0cm 0pt 21pt">LuaCall.cpp</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaObject.cpp</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaPlus.cpp</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaPlusAddons.c</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaPlusFunctions.cpp</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaPlus_Libs.cpp</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaStackObject.cpp</p></td>
<td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; font-size: 12px; border-left-color: rgb(236,233,216); padding-bottom: 0cm; width: 213.05pt; color: rgb(69,69,69); line-height: 16px; padding-top: 0cm; border-bottom: windowtext 1pt solid; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: transparent; word-wrap: break-word" valign="top" width="284">
<p style="margin: 0cm 0cm 0pt 21pt">LuaStackTableIterator.cpp</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaState.cpp</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaStateOutFile.cpp</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaState_DumpObject.cpp</p>
<p style="margin: 0cm 0cm 0pt 21pt">LuaTableIterator.cpp</p>
<p style="margin: 0cm 0cm 0pt 21pt">lwstrlib.c</p></td></tr></tbody></table></p>
<p style="margin: 0cm 0cm 0pt 21pt">&nbsp;</p>
<p>&nbsp;</p>
<p style="margin: 0cm 0cm 0pt 18pt; text-indent: -18pt"><strong><span style="color: maroon">3.<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></strong><strong><span style="color: maroon; font-family: 宋体">建立项目</span></strong></p>
<p><span style="font-family: 宋体">然后你就可以在</span>VS<span style="font-family: 宋体">中建立一个新项目</span>,<span style="font-family: 宋体">静态链接库的</span>:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://www.cppblog.com/images/cppblog_com/singohgod/4054/o_1.jpg" border="0"  alt="" /></p>
<p><span style="font-family: 宋体">分别把需要的文件加进去</span>,<span style="font-family: 宋体">之后编译</span>,<span style="font-family: 宋体">应该能通过了</span>.</p>
<p>&nbsp;</p>
<p><strong><span style="font-size: 14pt; color: red; font-family: 宋体">如何使用</span></strong><strong></strong></p>
<p><span style="font-family: 宋体">接着讲讲如何在你的其他项目中使用</span>LuaPlus.</p>
<p><strong><span style="color: maroon">1.</span></strong><strong><span style="color: maroon; font-family: 宋体">必要的配置</span></strong></p>
<p><span style="font-family: 宋体">你的项目可能是这样的</span>:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://www.cppblog.com/images/cppblog_com/singohgod/4054/o_2.jpg" border="0"  alt="" /></p>
<p><span style="font-family: 宋体">设置</span>GameClient<span style="font-family: 宋体">的依赖项是</span>LuaPlusLib</p>
<p><span style="color: blue">#include "LuaPlus.h"</span></p>
<p><span style="color: blue">using namespace LuaPlus;</span></p>
<p><span style="font-family: 宋体">记得干这事</span>&#8230;</p>
<p>&nbsp;</p>
<p><strong><span style="color: maroon">2.</span></strong><strong><span style="color: maroon; font-family: 宋体">创建一个状态</span></strong></p>
<p><span style="color: blue">LuaStateOwner state;</span></p>
<p><span style="font-family: 宋体">今后的操作都围绕这个</span>state</p>
<p style="margin: 0cm 0cm 0pt 21pt">&nbsp;</p>
<p><strong><span style="color: maroon">3.</span></strong><strong><span style="color: maroon; font-family: 宋体">执行脚本</span></strong></p>
<p><span style="color: blue">int iret = state-&gt;DoFile("test.lua");</span></p>
<p><span style="font-family: 宋体">返回值为</span>0<span style="font-family: 宋体">表示成功</span>,<span style="font-family: 宋体">否则不成功</span>.</p>
<p style="margin: 0cm 0cm 0pt 21pt">&nbsp;</p>
<p><strong><span style="color: maroon">4.C++</span></strong><strong><span style="color: maroon; font-family: 宋体">中获取</span><span style="color: maroon">Lua</span></strong><strong><span style="color: maroon; font-family: 宋体">脚本的变量</span></strong></p>
<p><span style="font-family: 宋体">假设你的</span>test.lua<span style="font-family: 宋体">中有</span>:</p>
<p>health = 200;</p>
<p><span style="font-family: 宋体">通过下列方法就可以在</span>C++<span style="font-family: 宋体">中得到这个数值</span></p>
<p><span style="color: blue">int mytest = state-&gt;GetGlobal("health").GetInteger();</span></p>
<p style="margin: 0cm 0cm 0pt 21pt">&nbsp;</p>
<p><strong><span style="color: maroon">5.C++</span></strong><strong><span style="color: maroon; font-family: 宋体">中调用</span><span style="color: maroon">Lua</span></strong><strong><span style="color: maroon; font-family: 宋体">脚本里的函数</span></strong></p>
<p><span style="font-family: 宋体">假设你的</span>test.lua<span style="font-family: 宋体">中有</span>:</p>
<p><span style="color: blue">function Add(x, y)</span></p>
<p><span style="color: blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return x+y;</span></p>
<p><span style="color: blue">end</span></p>
<p><span style="font-family: 宋体">在</span>C++<span style="font-family: 宋体">中需要先声明这个函数</span>:</p>
<p><span style="color: blue">LuaFunction&lt;float&gt; Add =&nbsp;&nbsp;state-&gt;GetGlobal("Add");</span></p>
<p><span style="font-family: 宋体">这样你就有了</span>Add()<span style="font-family: 宋体">这个函数</span>,<span style="font-family: 宋体">然后就可以像平常一样使用它了</span>:</p>
<p><span style="color: blue">float myret = Add(3.14f,5.25f);</span></p>
<p style="margin: 0cm 0cm 0pt 21pt">&nbsp;</p>
<p><strong><span style="color: maroon">6.Lua</span></strong><strong><span style="color: maroon; font-family: 宋体">脚本中调用</span><span style="color: maroon">C++</span></strong><strong><span style="color: maroon; font-family: 宋体">函数</span></strong></p>
<p><span style="font-family: 宋体">在读取</span>test.lua<span style="font-family: 宋体">之前要先把</span>C++<span style="font-family: 宋体">函数注册到</span>Lua<span style="font-family: 宋体">的运行时栈里</span>,<span style="font-family: 宋体">这样在执行</span>lua<span style="font-family: 宋体">脚本的时候</span>,<span style="font-family: 宋体">才知道执行哪一个函数</span>:</p>
<p><span style="font-family: 宋体">首先有函数</span>:</p>
<p><span style="color: blue">int LS_PrintNumber(LuaState* state)</span></p>
<p><span style="color: blue">{</span></p>
<p style="margin: 0cm 0cm 0pt 21pt"><span style="color: blue">LuaStack args(state);</span></p>
<p>&nbsp;</p>
<p><span style="color: blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (args[1].IsNumber()) {</span></p>
<p><span style="color: blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%f\n", args[1].GetNumber());</span></p>
<p><span style="color: blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></p>
<p><span style="color: blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;</span></p>
<p><span style="color: blue">}</span></p>
<p><span style="font-family: 宋体">然后注册这个函数到</span>Lua:</p>
<p><span style="color: blue">state-&gt;GetGlobals().Register("PrintNumber", LS_PrintNumber);</span></p>
<p><span style="font-family: 宋体">这样就把</span>LS_PrintNumber<span style="font-family: 宋体">映射为</span>Lua<span style="font-family: 宋体">中可以使用的函数</span>PrintNumber.</p>
<p>Test.lua<span style="font-family: 宋体">脚本中添加调用语句</span>:</p>
<p><span style="color: blue">PrintNumber(30);</span></p>
<p><span style="font-family: 宋体">当</span><span style="color: blue">state-&gt;DoFile("test.lua");</span><span style="font-family: 宋体">执行的时候</span>,<span style="font-family: 宋体">就执行了</span>C++<span style="font-family: 宋体">中的这个函数</span>.</p>
<p>&nbsp;</p>
<p><strong><span style="font-size: 14pt; color: red; font-family: 宋体">总结</span></strong><strong></strong></p>
<p><span style="font-family: 宋体">本文介绍了</span>LuaPlus<span style="font-family: 宋体">的基本配置方法和使用</span>,<span style="font-family: 宋体">希望对你有帮助</span>.<span style="font-family: 宋体">下一篇将介绍一些高级特性</span>,<span style="font-family: 宋体">如怎样在</span>VS<span style="font-family: 宋体">中调试</span>LuaPlus<span style="font-family: 宋体">的脚本</span>,<span style="font-family: 宋体">以及对类的操作等</span>.<br /></p>
<p>如果还有任何疑问可以看看下面这个简单的例子:<br />&nbsp;<a style="color: rgb(26,139,200); text-decoration: none" href="http://www.cppblog.com/Files/singohgod/LuaPlus_Test.rar">/Files/singohgod/LuaPlus_Test.rar</a></p></span><img src ="http://www.cppblog.com/wc250en007/aggbug/151284.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-07-18 10:10 <a href="http://www.cppblog.com/wc250en007/archive/2011/07/18/151284.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>luaplus学习(二) 转</title><link>http://www.cppblog.com/wc250en007/archive/2011/07/18/151283.html</link><dc:creator>Let me see see</dc:creator><author>Let me see see</author><pubDate>Mon, 18 Jul 2011 02:08:00 GMT</pubDate><guid>http://www.cppblog.com/wc250en007/archive/2011/07/18/151283.html</guid><wfw:comment>http://www.cppblog.com/wc250en007/comments/151283.html</wfw:comment><comments>http://www.cppblog.com/wc250en007/archive/2011/07/18/151283.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wc250en007/comments/commentRss/151283.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wc250en007/services/trackbacks/151283.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); 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"> 
<h1 style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">用lua做配置文件</h1>&nbsp;&nbsp;&nbsp; 可以用lua做程序的配置文件。<br />&nbsp;&nbsp;&nbsp; LuaPlus提供了读写lua脚本文件的功能，我们可以将配置信息以Table的形式存储在lua脚本中，然后利用LuaPlus进行读取和更改。<br />
<h2 style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">&nbsp;&nbsp;&nbsp; 一、创建配置文件</h2>&nbsp;&nbsp;&nbsp; 配置文件可以用文字编辑器创建，也可以在C++代码中创建。我们先在C++中创建。利用CreateTable创建一个名为"Window"的表格，利用LuaObject的Set*函数设置表格内容，最后用DumpObject函数保存到文件。代码如下：<br />
<div style="border-right: windowtext 0.5pt solid; padding-right: 5.4pt; background-position: 0% 50%; border-top: windowtext 0.5pt solid; padding-left: 5.4pt; background-attachment: scroll;background-image: none; padding-bottom: 4px; border-left: windowtext 0.5pt solid; width: 659px; padding-top: 4px; border-bottom: windowtext 0.5pt solid; background-color: rgb(230,230,230); background-origin: initial; background-clip: initial">
<div><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)">&nbsp;SaveTable()<br /><img id="_17_431_Open_Image" style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" onclick="this.style.display='none'; document.getElementById('_17_431_Open_Text').style.display='none'; document.getElementById('_17_431_Closed_Image').style.display='inline'; document.getElementById('_17_431_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top"></span><span id="_17_431_Open_Text"><span style="color: rgb(0,0,0)">{<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;LuaStateOwner&nbsp;state;<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;LuaObject&nbsp;myTable&nbsp;</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">&nbsp;&nbsp;state</span><span style="color: rgb(0,0,0)">-&gt;</span><span style="color: rgb(0,0,0)">GetGlobals().CreateTable(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">Window</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;myTable.SetInteger(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">width</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;</span><span style="color: rgb(0,0,0)">640</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;myTable.SetInteger(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">height</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;</span><span style="color: rgb(0,0,0)">480</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;myTable.SetString(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">title</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">My&nbsp;First&nbsp;Window</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;myTable.SetBoolean(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">enabled</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;</span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;myTable.SetInteger(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">alpha</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;</span><span style="color: rgb(0,0,0)">128</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;myTable.SetString(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">backgroundimage</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">bg.jpg</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;state</span><span style="color: rgb(0,0,0)">-&gt;</span><span style="color: rgb(0,0,0)">DumpObject(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">FirstWindow.lua</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">Window</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;state</span><span style="color: rgb(0,0,0)">-&gt;</span><span style="color: rgb(0,0,0)">GetGlobals()[</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">Window</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">],&nbsp;</span><span style="color: rgb(0,0,0)">0</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></div>&nbsp;&nbsp;&nbsp; 相关函数的说明参见文档。<br />
<h2 style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">&nbsp;&nbsp;&nbsp; 二、读取配置文件</h2>&nbsp;&nbsp;&nbsp; Lua配置文件的加载和其它脚本文件一样，可以用DoFile函数，然后可以用GetGlobals加索引的形式获取表格LuaObject对象，最后用[ ]访问表格的元素。代码如下：<br />
<div style="border-right: windowtext 0.5pt solid; padding-right: 5.4pt; background-position: 0% 50%; border-top: windowtext 0.5pt solid; padding-left: 5.4pt; background-attachment: scroll;background-image: none; padding-bottom: 4px; border-left: windowtext 0.5pt solid; width: 659px; padding-top: 4px; border-bottom: windowtext 0.5pt solid; background-color: rgb(230,230,230); background-origin: initial; background-clip: initial">
<div><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)">&nbsp;ReadShowTable()<br /><img id="_21_603_Open_Image" style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" onclick="this.style.display='none'; document.getElementById('_21_603_Open_Text').style.display='none'; document.getElementById('_21_603_Closed_Image').style.display='inline'; document.getElementById('_21_603_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top"></span><span id="_21_603_Open_Text"><span style="color: rgb(0,0,0)">{<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;LuaStateOwner&nbsp;state;<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;state</span><span style="color: rgb(0,0,0)">-&gt;</span><span style="color: rgb(0,0,0)">DoFile(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">FirstWindow.lua</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;LuaObject&nbsp;myTable&nbsp;</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">&nbsp;state</span><span style="color: rgb(0,0,0)">-&gt;</span><span style="color: rgb(0,0,0)">GetGlobals()[</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">Window</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">];<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">get&nbsp;Window&nbsp;Table's&nbsp;item</span><span style="color: rgb(0,128,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">Window&nbsp;Table&nbsp;in&nbsp;FirstWindow.lua:<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)"> width&nbsp;=&nbsp;%d<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;myTable[</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">width</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">].GetInteger()&nbsp;);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)"> height&nbsp;=&nbsp;%d<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;myTable[</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">height</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">].GetInteger()&nbsp;);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)"> title&nbsp;=&nbsp;%s<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;myTable[</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">title</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">].GetString()&nbsp;);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)"> enabled&nbsp;=&nbsp;%s<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;myTable[</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">enabled</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">].GetBoolean()&nbsp;</span><span style="color: rgb(0,0,0)">?</span><span style="color: rgb(0,0,0)">&nbsp;</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">true</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">&nbsp;:&nbsp;</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">false</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">&nbsp;);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)"> alpha&nbsp;=&nbsp;%d<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;myTable[</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">alpha</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">].GetInteger());<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)"> backgroundimage&nbsp;=&nbsp;%s<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;myTable[</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">backgroundimage</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">].GetString()&nbsp;);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></div><br />
<h2 style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">&nbsp;&nbsp;&nbsp; 三、更改配置文件</h2>&nbsp;&nbsp;&nbsp; 读取配置文件的过程和上一节类似，更改与保存和第一节类似。代码如下：<br />
<div style="border-right: windowtext 0.5pt solid; padding-right: 5.4pt; background-position: 0% 50%; border-top: windowtext 0.5pt solid; padding-left: 5.4pt; background-attachment: scroll;background-image: none; padding-bottom: 4px; border-left: windowtext 0.5pt solid; width: 659px; padding-top: 4px; border-bottom: windowtext 0.5pt solid; background-color: rgb(230,230,230); background-origin: initial; background-clip: initial">
<div><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)">&nbsp;RewriteTableContents()<br /><img id="_28_392_Open_Image" style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" onclick="this.style.display='none'; document.getElementById('_28_392_Open_Text').style.display='none'; document.getElementById('_28_392_Closed_Image').style.display='inline'; document.getElementById('_28_392_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top"></span><span id="_28_392_Open_Text"><span style="color: rgb(0,0,0)">{<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;LuaStateOwner&nbsp;state;<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;state</span><span style="color: rgb(0,0,0)">-&gt;</span><span style="color: rgb(0,0,0)">DoFile(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">FirstWindow.lua</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;LuaObject&nbsp;myTable&nbsp;</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">&nbsp;state</span><span style="color: rgb(0,0,0)">-&gt;</span><span style="color: rgb(0,0,0)">GetGlobals()[</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">Window</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">];<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;myTable.SetInteger(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">width</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;</span><span style="color: rgb(0,0,0)">800</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;myTable.SetInteger(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">height</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;</span><span style="color: rgb(0,0,0)">600</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">new&nbsp;width=%d,&nbsp;height=%d<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,myTable[</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">width</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">].GetInteger(),&nbsp;myTable[</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">height</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">].GetInteger());<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;state</span><span style="color: rgb(0,0,0)">-&gt;</span><span style="color: rgb(0,0,0)">DumpObject(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">FirstWindow.lua</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">Window</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;state</span><span style="color: rgb(0,0,0)">-&gt;</span><span style="color: rgb(0,0,0)">GetGlobals()[</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">Window</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">]);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></div>&nbsp;&nbsp;&nbsp; 值得注意的是，更新配置文件时，不能单独更新表格的某一个元素。我试验了下，出错。也许是我的方法不对。所以我现在一次更新整个表格。<br /><br />&nbsp;&nbsp;&nbsp; 下面是main函数：<br />&nbsp;&nbsp;&nbsp; 
<div style="border-right: windowtext 0.5pt solid; padding-right: 5.4pt; background-position: 0% 50%; border-top: windowtext 0.5pt solid; padding-left: 5.4pt; background-attachment: scroll;background-image: none; padding-bottom: 4px; border-left: windowtext 0.5pt solid; width: 659px; padding-top: 4px; border-bottom: windowtext 0.5pt solid; background-color: rgb(230,230,230); background-origin: initial; background-clip: initial">
<div><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">&nbsp;_tmain(</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">&nbsp;argc,&nbsp;_TCHAR</span><span style="color: rgb(0,0,0)">*</span><span style="color: rgb(0,0,0)">&nbsp;argv[])<br /><img id="_37_381_Open_Image" style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" onclick="this.style.display='none'; document.getElementById('_37_381_Open_Text').style.display='none'; document.getElementById('_37_381_Closed_Image').style.display='inline'; document.getElementById('_37_381_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top"></span><span id="_37_381_Open_Text"><span style="color: rgb(0,0,0)">{<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">now&nbsp;create&nbsp;table&nbsp;and&nbsp;save&nbsp;in&nbsp;FirstWindow.lua:<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;SaveTable();<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">now&nbsp;read&nbsp;table&nbsp;from&nbsp;FirstWindow.lua:<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;ReadShowTable();<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">now&nbsp;retrieve&nbsp;the&nbsp;table,&nbsp;change&nbsp;the&nbsp;"width"&nbsp;and&nbsp;"height"&nbsp;value,&nbsp;then&nbsp;save:<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;RewriteTableContents();<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">now,&nbsp;re-read&nbsp;from&nbsp;FirstWindow.lua:<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;ReadShowTable();<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,0)">&nbsp;</span><span style="color: rgb(0,0,0)">0</span><span style="color: rgb(0,0,0)">;<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></div><br />&nbsp;&nbsp;&nbsp; 工程的设置和上一篇文章一样。<br />&nbsp;&nbsp;&nbsp; F7编译后CTRL+F5即可看到运行结果。<br /><br />&nbsp;&nbsp;&nbsp; 值得注意的是，table可以嵌套table。这样我们便可以实现复杂的配置文件。</span><img src ="http://www.cppblog.com/wc250en007/aggbug/151283.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-07-18 10:08 <a href="http://www.cppblog.com/wc250en007/archive/2011/07/18/151283.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>luaplus学习（一） 转</title><link>http://www.cppblog.com/wc250en007/archive/2011/07/18/151282.html</link><dc:creator>Let me see see</dc:creator><author>Let me see see</author><pubDate>Mon, 18 Jul 2011 02:07:00 GMT</pubDate><guid>http://www.cppblog.com/wc250en007/archive/2011/07/18/151282.html</guid><wfw:comment>http://www.cppblog.com/wc250en007/comments/151282.html</wfw:comment><comments>http://www.cppblog.com/wc250en007/archive/2011/07/18/151282.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wc250en007/comments/commentRss/151282.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wc250en007/services/trackbacks/151282.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); 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">&nbsp;&nbsp;&nbsp; 想在我的项目中使用Lua脚本语言。最初知道Lua是通过CEGUI，后来因为一些原因不打算使用CEGUI了，只好单独使用Lua。在网上看到LuaPlus，貌似比较简单。在此记录学习过程。<br />&nbsp;&nbsp;&nbsp; 可以到这里http://luaplus.org/tiki-index.php?page=LuaPlus+Home+Page下载LuaPlus的win32二进制文件和源码包。从源码包提取头文件，从二进制包提取DLL文件。<br />&nbsp;&nbsp;&nbsp; LuaPlus对Lua做了修改和封装，使得Lua和C++的交互更为简单。可以从上面的链接找到它的介绍。<br /><br />&nbsp;&nbsp;&nbsp; 先简单的做两个测试：（1）从C++中调用Lua脚本中的函数；（2）从Lua脚本中调用C++里的函数。<br /><br />
<h2 style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">&nbsp;&nbsp;&nbsp; 一、工程配置</h2>&nbsp;&nbsp;&nbsp; VC7.1中新建win32控制台工程TestLuaPlusLib。<br /><br />&nbsp;&nbsp;&nbsp; 解决方案视图中右键点击TestLuaPlusLib，选属性；配置组合框选&#8220;所有配置&#8221;；依次点击&#8220;配置属性&#8221;、&#8220;C/C++&#8221;、&#8220;常规&#8221;，在附加包含目录里添加源码解压后所在的路径（我的：E:/sources/LuaPlus/LuaPlus51_Build1100/Src/LuaPlus）；依次点击&#8220;连接器&#8221;、&#8220;常规&#8221;，在附加库目录中添加二进制包解压后所在的路径（我的：E:/sources/LuaPlus/LuaPlus51_Build1100_Win32/Lib/win32）。<br /><br />&nbsp;&nbsp;&nbsp; 在TestLuaPlusLib.cpp中加入如下几行代码，将头文件和库文件加入进来。<br /><br />
<div>
<div style="border-right: windowtext 0.5pt solid; padding-right: 5.4pt; background-position: 0% 50%; border-top: windowtext 0.5pt solid; padding-left: 5.4pt; background-attachment: scroll;background-image: none; padding-bottom: 4px; border-left: windowtext 0.5pt solid; width: 659px; padding-top: 4px; border-bottom: windowtext 0.5pt solid; background-color: rgb(230,230,230); background-origin: initial; background-clip: initial">
<div><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;#include&nbsp;</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">luaplus.h</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">#if</span><span style="color: rgb(0,0,0)">&nbsp;defined(DEBUG)&nbsp;||&nbsp;defined(_DEBUG)</span><span style="color: rgb(0,0,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">#pragma</span><span style="color: rgb(0,0,0)">&nbsp;comment(lib,&nbsp;"LuaPlusD_1100.lib")</span><span style="color: rgb(0,0,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">#else</span><span style="color: rgb(0,0,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">#pragma</span><span style="color: rgb(0,0,0)">&nbsp;comment(lib,&nbsp;"LuaPlus_1100.lib")</span><span style="color: rgb(0,0,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">#endif</span><span style="color: rgb(0,0,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)">&nbsp;</span><span style="color: rgb(0,0,255)">namespace</span><span style="color: rgb(0,0,0)">&nbsp;LuaPlus;<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span></div></div><br />&nbsp;&nbsp;&nbsp; 工程配置基本上完成了。</div>&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br />
<h2 style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">&nbsp;&nbsp; 二、测试用Lua脚本</h2>&nbsp;&nbsp;&nbsp; 如下建立测试用的Lua脚本并保存在你即将生成的可执行文件所在的目录下。同时需要把二进制包中的LuaPlusD_1100.dll和LuaPlus_1100.dll拷贝到该目录下。<br />
<div style="border-right: windowtext 0.5pt solid; padding-right: 5.4pt; background-position: 0% 50%; border-top: windowtext 0.5pt solid; padding-left: 5.4pt; background-attachment: scroll;background-image: none; padding-bottom: 4px; border-left: windowtext 0.5pt solid; width: 659px; padding-top: 4px; border-bottom: windowtext 0.5pt solid; background-color: rgb(230,230,230); background-origin: initial; background-clip: initial">
<div><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;health&nbsp;</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">&nbsp;</span><span style="color: rgb(0,0,0)">100</span><span style="color: rgb(0,0,0)">;<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;PrintNumber(</span><span style="color: rgb(0,0,0)">30</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />&nbsp;<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;Add(x,&nbsp;y)<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,0)">&nbsp;x&nbsp;</span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)">&nbsp;y;<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;end<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span></div></div><br />
<div>&nbsp;&nbsp;&nbsp; health = 100;Lua脚本中的全局变量，可以被C++文件访问。<br />&nbsp;&nbsp;&nbsp; PrintNumber(30);该语句调用C++文件中的函数，打印数字到控制台窗口。<br />&nbsp;&nbsp;&nbsp; function Add(x,y)声明一个函数，C++文件会找到并调用此函数。<br /><br />
<h2 style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">&nbsp;&nbsp;&nbsp; 三、C++实现</h2>&nbsp;&nbsp;&nbsp; 在TestLuaPlusLib.cpp中加入下面两个函数。<br />
<div style="border-right: windowtext 0.5pt solid; padding-right: 5.4pt; background-position: 0% 50%; border-top: windowtext 0.5pt solid; padding-left: 5.4pt; background-attachment: scroll;background-image: none; padding-bottom: 4px; border-left: windowtext 0.5pt solid; width: 659px; padding-top: 4px; border-bottom: windowtext 0.5pt solid; background-color: rgb(230,230,230); background-origin: initial; background-clip: initial">
<div><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,0)">&nbsp;</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">&nbsp;PrintLSNumber(LuaState</span><span style="color: rgb(0,0,0)">*</span><span style="color: rgb(0,0,0)">&nbsp;state)<br /><img id="_42_210_Open_Image" style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" onclick="this.style.display='none'; document.getElementById('_42_210_Open_Text').style.display='none'; document.getElementById('_42_210_Closed_Image').style.display='inline'; document.getElementById('_42_210_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top"></span><span id="_42_210_Open_Text"><span style="color: rgb(0,0,0)">{<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;LuaStack&nbsp;args(state);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">&nbsp;Verify&nbsp;it&nbsp;is&nbsp;a&nbsp;number&nbsp;and&nbsp;print&nbsp;it.</span><span style="color: rgb(0,128,0)"><br /><img id="_133_175_Open_Image" style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" onclick="this.style.display='none'; document.getElementById('_133_175_Open_Text').style.display='none'; document.getElementById('_133_175_Closed_Image').style.display='inline'; document.getElementById('_133_175_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"></span><span style="color: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)">&nbsp;(args[</span><span style="color: rgb(0,0,0)">1</span><span style="color: rgb(0,0,0)">].IsNumber())&nbsp;</span><span id="_133_175_Open_Text"><span style="color: rgb(0,0,0)">{<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">%f<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;args[</span><span style="color: rgb(0,0,0)">1</span><span style="color: rgb(0,0,0)">].GetNumber());<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: rgb(0,0,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">&nbsp;No&nbsp;return&nbsp;values.</span><span style="color: rgb(0,128,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,0)">&nbsp;</span><span style="color: rgb(0,0,0)">0</span><span style="color: rgb(0,0,0)">;<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0,0,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)">&nbsp;test()&nbsp;<br /><img id="_227_906_Open_Image" style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" onclick="this.style.display='none'; document.getElementById('_227_906_Open_Text').style.display='none'; document.getElementById('_227_906_Closed_Image').style.display='inline'; document.getElementById('_227_906_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top"></span><span id="_227_906_Open_Text"><span style="color: rgb(0,0,0)">{<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">Create&nbsp;state</span><span style="color: rgb(0,128,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;LuaStateOwner&nbsp;state;<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">With&nbsp;this&nbsp;the&nbsp;script&nbsp;can&nbsp;access&nbsp;our&nbsp;own&nbsp;C++&nbsp;functions:</span><span style="color: rgb(0,128,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;state</span><span style="color: rgb(0,0,0)">-&gt;</span><span style="color: rgb(0,0,0)">GetGlobals().Register(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">PrintNumber</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;PrintLSNumber);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">Open&nbsp;test&nbsp;file:</span><span style="color: rgb(0,128,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">&nbsp;iret&nbsp;</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">&nbsp;state</span><span style="color: rgb(0,0,0)">-&gt;</span><span style="color: rgb(0,0,0)">DoFile(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">test.lua</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">Get&nbsp;a&nbsp;global&nbsp;variable:</span><span style="color: rgb(0,128,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;LuaObject&nbsp;sObj&nbsp;</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">&nbsp;state</span><span style="color: rgb(0,0,0)">-&gt;</span><span style="color: rgb(0,0,0)">GetGlobal(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">health</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">&nbsp;mytest&nbsp;</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">&nbsp;sObj.GetInteger();<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">init&nbsp;value&nbsp;in&nbsp;luascript:%d<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;mytest);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">Update&nbsp;the&nbsp;value:</span><span style="color: rgb(0,128,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;sObj.AssignInteger(state,&nbsp;</span><span style="color: rgb(0,0,0)">50</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">Get&nbsp;value&nbsp;again:</span><span style="color: rgb(0,128,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;mytest&nbsp;</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">&nbsp;sObj.GetInteger();<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">after&nbsp;changed&nbsp;by&nbsp;c++:%d<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;mytest);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">Call&nbsp;a&nbsp;function&nbsp;in&nbsp;lua:</span><span style="color: rgb(0,128,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;LuaFunction</span><span style="color: rgb(0,0,0)">&lt;</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">&gt;</span><span style="color: rgb(0,0,0)">&nbsp;Add&nbsp;</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">&nbsp;&nbsp;state</span><span style="color: rgb(0,0,0)">-&gt;</span><span style="color: rgb(0,0,0)">GetGlobal(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">Add</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">&nbsp;myret&nbsp;</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">&nbsp;Add(</span><span style="color: rgb(0,0,0)">3</span><span style="color: rgb(0,0,0)">,&nbsp;</span><span style="color: rgb(0,0,0)">4</span><span style="color: rgb(0,0,0)">);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">Call&nbsp;add()&nbsp;in&nbsp;luascript,ret=%d<span class="Apple-converted-space">&nbsp;</span></span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">,&nbsp;myret);<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0,0,0)"><br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span></div></div><br />&nbsp;&nbsp;&nbsp; main函数：<br />
<div style="border-right: windowtext 0.5pt solid; padding-right: 5.4pt; background-position: 0% 50%; border-top: windowtext 0.5pt solid; padding-left: 5.4pt; background-attachment: scroll;background-image: none; padding-bottom: 4px; border-left: windowtext 0.5pt solid; width: 659px; padding-top: 4px; border-bottom: windowtext 0.5pt solid; background-color: rgb(230,230,230); background-origin: initial; background-clip: initial">
<div><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">&nbsp;_tmain(</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">&nbsp;argc,&nbsp;_TCHAR</span><span style="color: rgb(0,0,0)">*</span><span style="color: rgb(0,0,0)">&nbsp;argv[])<br /><img id="_37_59_Open_Image" style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" onclick="this.style.display='none'; document.getElementById('_37_59_Open_Text').style.display='none'; document.getElementById('_37_59_Closed_Image').style.display='inline'; document.getElementById('_37_59_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top"></span><span id="_37_59_Open_Text"><span style="color: rgb(0,0,0)">{<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;test();<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,0)">&nbsp;</span><span style="color: rgb(0,0,0)">0</span><span style="color: rgb(0,0,0)">;<br /><img style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></div></div>
<div>&nbsp;<br />&nbsp;&nbsp;&nbsp; 现在可以编译了，编译完成之后运行，可以在控制台窗口中看到结果。<br />&nbsp;&nbsp;&nbsp; 需要注意的是执行脚本要在注册C++函数到Lua模块之后进行。<br />&nbsp;&nbsp;&nbsp; 基本上是按照http://gpwiki.org/index.php/Scripting_with_LuaPlus_and_Cpp来做的，加入了工程设置部分。该链接的代码（test函数）会报错（调用了math库中的cos函数，但是没有调用OpenLibs()函数），我修改了一下，去掉了对math库的引用。<br /><br />
<h3 style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">&nbsp;&nbsp; 相关资源链接：</h3>&nbsp;&nbsp;&nbsp; 1&gt;LuaPlus的文档：http://www.gamedev.net/reference/programming/features/lua/<br />&nbsp;&nbsp;&nbsp; 2&gt;LuaPlus初级教程：http://wwhiz.com/LuaPlus/LuaPlus.html</div></span><img src ="http://www.cppblog.com/wc250en007/aggbug/151282.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-07-18 10:07 <a href="http://www.cppblog.com/wc250en007/archive/2011/07/18/151282.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>