﻿<?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++博客-创的技术博客-随笔分类-脚本语言</title><link>http://www.cppblog.com/converse/category/686.html</link><description>C++对我而言就是有STL带class能处理多态,继承的C.</description><language>zh-cn</language><lastBuildDate>Tue, 20 May 2008 14:03:48 GMT</lastBuildDate><pubDate>Tue, 20 May 2008 14:03:48 GMT</pubDate><ttl>60</ttl><item><title>使用tolua++创建基于C\C++语言的lua脚本</title><link>http://www.cppblog.com/converse/archive/2005/12/27/2199.html</link><dc:creator>创</dc:creator><author>创</author><pubDate>Tue, 27 Dec 2005 15:57:00 GMT</pubDate><guid>http://www.cppblog.com/converse/archive/2005/12/27/2199.html</guid><wfw:comment>http://www.cppblog.com/converse/comments/2199.html</wfw:comment><comments>http://www.cppblog.com/converse/archive/2005/12/27/2199.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/converse/comments/commentRss/2199.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/converse/services/trackbacks/2199.html</trackback:ping><description><![CDATA[<P align=left><FONT size=2><BR>2005年12月27日23:07:59<BR><BR>一.tolua++简介<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tolua++是一种第三方的软件包,可以为Lua提供面向对象的特性,这样我们就可以使用Lua来编写使用C++语言库的脚本文件.<BR></P></FONT><FONT size=2>
<P align=left><BR>二.tolua++的编译.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tolua++的主页在</FONT><A href="http://www.codenix.com/~tolua/"><FONT size=2>http://www.codenix.com/~tolua/</FONT></A><FONT size=2>,目前的最新版本是1.0.7,为了使用tolua++,我们需要三个文件:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.bin/tolua++[.exe] - tolua++的可执行程序<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.include/tolua++.h - tolua++的头文件<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.lib/libtolua++.a or lib/tolua++.lib - tolua++的静态库(当然有的时候也需要生成动态库,可以参考我下面给出的文章的网址,我们先从最简单的入手)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 使用tolua++的时候,都需要使用tolua++的可执行程序自动生成一个.pkg文件生成对应的.c(C语言)或者.cpp文件(C++语言),然后把这个文件和对应的C\C++文件一起编译生成可执行程序,这样就可以对对应的Lua脚本进行读取操作.在后面将结合代码例子对这个过程进行详细的讲解.</FONT></P>
<P align=left><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tolua++的编译比较麻烦,官方的编译说明需要scons这个软件,下面介绍另一种办法,只需要Lua就可以了(本身编写Lua脚本文件不可能不用到Lua解释器,所以这个算不上什么负担了:)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 说明一下,这个办法不是我想出来的,出处在这里:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><A href="http://lua-users.org/wiki/CompilingToluappWithoutScons"><FONT size=2>http://lua-users.org/wiki/CompilingToluappWithoutScons</FONT></A><BR><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 官方下载的tolua++文件夹里面已经有了上面提到的1和2文件了,我在这里偷懒,就只说3的生成.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其实在上面的文档里面写得很清楚了,如下编译生成静态库文件:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></P>
<DIV align=left>
<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"><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">tolua</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">_1.</SPAN><SPAN style="COLOR: #000000">0.5</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">\src\lib</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;gcc&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">c&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">.c&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">I..\..\include&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">I&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">path_to_lua</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">\include<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top>tolua</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">_1.</SPAN><SPAN style="COLOR: #000000">0.5</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">\src\lib</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;ar&nbsp;rcsv&nbsp;libtolua</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">.a&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">.o</SPAN></FONT></DIV></DIV>
<P align=left><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;path_to_lua&gt;的意思是这里输入的是lua源代码包的路径,gcc中的-I参数用于指定include文件的位置.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 生成了这三个文件之后,如果需要使用它们的话,需要把它们拷贝到相应的路径.windows下面一般的会使用cygwin这个工具,以它为例说明:<BR>1.可执行文件放在cygwin根目录的bin目录下<BR>2.头文件放在cygwin根目录下的usr\include下面<BR>3.静态头文件放在cygwin根目录下的lib目录下面<BR>说明:如果没有Lua语言的对应的可执行文件,头文件,lib文件一样不能使用tolua++,对于配置lua脚本解释器的过程和上面类似.<BR>OK,这样一个tolua++的编译环境就配制好了,如果你在原先安装cygwin的时候没有指定cygwin的可执行文件的目录,那么对于windows下面的用户可以在"我的电脑"-"属性"-"高级"-"环境变量"-"Path"里面修改,<BR>比如我在里面加入我的cygwin的bin目录:C:\cygwin\bin,大功告成~~windows下面的用户只用gcc的话不一定非得使用cygwin,毕竟太大了,有人喜欢使用mingw,配置的方法类似~~</FONT></P>
<P align=left><BR><FONT size=2>三.代码例子<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tolua++的源码包下载下来之后在根目录的src\tests中有很多代码例子,我们随便找其中的tarray一组作为讲解的对象.<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这一组中包含的有对应的pkg文件,c文件,h文件和最后用于测试的lua脚本文件.pkg文件是用于声明我们允许后来使用的Lua脚本使用的变量,常量,类,函数等等的一个声明列表,这个列表中的所有东西都必须在对应的C++文件中给出来,不然是无法使用的.pkg文件的语法和C\C++的语法比较类似,可以到tolua++的官方网站上去看看,这里不再详述.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 使用pkg文件我们可以生成一个对应的C或者C++文件,可以这样做:</FONT></P>
<DIV align=left>
<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"><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">tolua</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">o&nbsp;test.c&nbsp;tarray.pkg</SPAN></FONT></DIV></DIV>
<P align=left><BR><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 生成的test.c就是对应的c文件,你打开这个文件看看,基本上都需要上千行的代码.</FONT></P>
<P align=left><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 打开tarray.c看看,为了使用Lua我们还需要作些什么,除去基本的数据的定义和main之外,还需要这些:<BR>1.包含lua头文件:</FONT></P>
<DIV align=left>
<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"><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">#include&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">lualib.h</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top>#include&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">lauxlib.h</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN></DIV></DIV>
<P align=left><BR><FONT size=2>2.调用Lua脚本:<BR>省略去不重要的部分,有这些代码:</FONT></P>
<DIV align=left>
<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"><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;tolua_tarray_open&nbsp;(lua_State</SPAN><SPAN style="COLOR: #000000">*</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top>&nbsp;lua_State</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">&nbsp;L&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;lua_open();<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.cppblog.com/images/dot.gif">.</SPAN></FONT><SPAN style="COLOR: #008000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><FONT size=2><SPAN style="COLOR: #000000">&nbsp;luaopen_base(L);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top>&nbsp;tolua_tarray_open(L);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top>&nbsp;lua_dofile(L,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">tarray.lua</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">执行lua脚本</SPAN></FONT><SPAN style="COLOR: #008000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>&nbsp;lua_close(L);</FONT></SPAN></DIV></DIV>
<P align=left><FONT size=2></FONT>&nbsp;</P>
<P align=left><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OK,现在来看看如何使用:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 首先,生成tarray.o文件:</FONT></P>
<DIV align=left>
<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"><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">gcc&nbsp;tarray.c&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN></FONT><SPAN style="COLOR: #000000"><FONT size=2>c<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN></DIV></DIV>
<P align=left><BR><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其次,生成test.o文件:</FONT></P>
<DIV align=left>
<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"><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">gcc&nbsp;test.c&nbsp;tarray.h&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">c</SPAN></FONT></DIV></DIV>
<P align=left><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 最后,把两个文件链接起来,注意要加入Lua和tolua++的lib文件:</FONT></P>
<DIV align=left>
<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"><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">gcc&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">o&nbsp;tarray.exe&nbsp;tarray.o&nbsp;test.o&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">llua&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">llualib&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">ltolua</SPAN><SPAN style="COLOR: #000000">++</SPAN></FONT></DIV></DIV>
<P align=left><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 好了,现在大功告成,我们编写一段Lua代码调用C中的变量(源码中带有的tarray.lua基本上没有任何用途:)<BR></P></FONT>
<DIV align=left>
<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"><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;i</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">10</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">do</SPAN></FONT><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;print(a[i&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">1</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">])<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top>end<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;i</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">10</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">do</SPAN></FONT><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;print(p[i&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">1</SPAN></FONT><SPAN style="COLOR: #000000"><FONT size=2>].x)<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top>end<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN></DIV></DIV>
<P align=left><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OK,现在在命令行下面输入tarray.exe看看效果:</FONT></P>
<DIV align=left>
<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"><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">1</SPAN></FONT><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>2</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>3</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>4</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>5</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>6</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>7</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>8</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>9</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>10</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>1</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>2</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>3</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>4</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>5</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>6</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>7</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>8</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>9</FONT></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></FONT></SPAN></DIV></DIV>
<P align=left><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;可以看到简单的两个循环遍历C中的变量的效果就这样由lua脚本实现了,很简单,不是么:)</FONT></P>
<P align=left><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 总结一下使用tolua++的过程:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1)编写pkg文件生成对应的c\c++文件<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2)分别编译1)产生的文件(注意要加上对应的头文件)和需要使用lua脚本的文件<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3)编写lua脚本,遵从lua的语法并且使用到的变量,函数,类等都是1)中声明过的.</FONT></P>
<P align=left><FONT size=2></FONT>&nbsp;</P>
<P align=left><FONT size=2></FONT>&nbsp;</P>
<P align=left><FONT size=2></FONT>&nbsp;</P>
<P align=left><FONT size=2></FONT>&nbsp;</P>
<P align=left><FONT size=2></FONT>&nbsp;</P>
<P align=left><FONT size=2></FONT>&nbsp;</P>
<P align=left><FONT size=2></FONT>&nbsp;</P><img src ="http://www.cppblog.com/converse/aggbug/2199.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/converse/" target="_blank">创</a> 2005-12-27 23:57 <a href="http://www.cppblog.com/converse/archive/2005/12/27/2199.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>