﻿<?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>IT博客-kenlistian-随笔分类-AI</title><link>http://www.cnitblog.com/kenlistian/category/4534.html</link><description>勤学多思
</description><language>zh-cn</language><lastBuildDate>Wed, 05 Oct 2011 07:36:44 GMT</lastBuildDate><pubDate>Wed, 05 Oct 2011 07:36:44 GMT</pubDate><ttl>60</ttl><item><title>lua中的upvalues</title><link>http://www.cnitblog.com/kenlistian/archive/2008/10/27/50738.html</link><dc:creator>kenlistian</dc:creator><author>kenlistian</author><pubDate>Mon, 27 Oct 2008 08:56:00 GMT</pubDate><guid>http://www.cnitblog.com/kenlistian/archive/2008/10/27/50738.html</guid><wfw:comment>http://www.cnitblog.com/kenlistian/comments/50738.html</wfw:comment><comments>http://www.cnitblog.com/kenlistian/archive/2008/10/27/50738.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/kenlistian/comments/commentRss/50738.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/kenlistian/services/trackbacks/50738.html</trackback:ping><description><![CDATA[理解Upvalues<br><br>把它理解为一个与C static变量等价的东西即可。<br><br><br>如下函数：<br>&nbsp;<br>&nbsp;static int counter(lua_State* L);<br><br>&nbsp;int newCounter(Lua_State* L){<br>&nbsp;&nbsp; lua_pushnumber(L, 0);<br>&nbsp;&nbsp; lua_pushcclosure(L, &amp;counter, 1);<br>&nbsp;&nbsp; return 1;<br>&nbsp; }<br><br>&nbsp; 其中调用lua_pushcclosure 函数，就是创建了一个闭包函数，<br>&nbsp; 即在该counter函数中，可以使用由<br>&nbsp; &nbsp; &nbsp; lua_pushnumber&nbsp; 压入的初始值0。<br>&nbsp; 其中压入一个upvalues值，则在pushcclosure第三个参数个数则为1.<br><br>&nbsp; 在函数中<br>&nbsp; static int counter (lua_State *L) <br>&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp; double val = lua_tonumber(L, lua_upvalueindex(1)); <br>&nbsp;&nbsp;&nbsp;&nbsp; lua_pushnumber(L, ++val);&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; lua_pushvalue(L, -1);&nbsp; &nbsp; &nbsp; &nbsp; /* duplicate it */ <br>&nbsp;&nbsp;&nbsp;&nbsp; lua_replace(L, lua_upvalueindex(1)); <br>&nbsp;&nbsp;&nbsp;&nbsp; return 1; <br>&nbsp; } <br><br>&nbsp; lua_upvaluesindex(1) ,就是取出upvalues值，其索引为第一个参数。<br>&nbsp; 由于这个参数并不是堆栈中索引，而是仅仅表示参数序位的索引，即，取出<br>&nbsp; upvalue的当前值。&nbsp; <br>&nbsp;&nbsp; <br><br><br><br><br><br><br><br>&nbsp; <br><br>&nbsp;<br><br><br> <img src ="http://www.cnitblog.com/kenlistian/aggbug/50738.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/kenlistian/" target="_blank">kenlistian</a> 2008-10-27 16:56 <a href="http://www.cnitblog.com/kenlistian/archive/2008/10/27/50738.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>lua 元表概念</title><link>http://www.cnitblog.com/kenlistian/archive/2008/10/19/50403.html</link><dc:creator>kenlistian</dc:creator><author>kenlistian</author><pubDate>Sun, 19 Oct 2008 06:44:00 GMT</pubDate><guid>http://www.cnitblog.com/kenlistian/archive/2008/10/19/50403.html</guid><wfw:comment>http://www.cnitblog.com/kenlistian/comments/50403.html</wfw:comment><comments>http://www.cnitblog.com/kenlistian/archive/2008/10/19/50403.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/kenlistian/comments/commentRss/50403.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/kenlistian/services/trackbacks/50403.html</trackback:ping><description><![CDATA[这个是lua中需要理解的概念，以前写过关于元表的笔记，好久没摸，又忘了。<br><br><br>元表概念 （ Metatable）<br>&nbsp; 元表由键名为 事件 (event) 和其中的值叫作元方法 (metamethod)组成。<br>&nbsp; <br>&nbsp; 在lua中每个值都有一个元表。而table和userdata所定义的值允许自定义对应的元表，<br>&nbsp; 其他都是用统一的元表。<br><br>&nbsp; 我的理解，元表，其实有点类似<span style="color: red;">值的属性</span>的味道。<br><br>对元表的操作<br>getmetable 查询元方法<br>setmetable 替换元方法。<br><br>metatable 包含几个固定的元方法.<br>&nbsp;&nbsp; 其事件名由下划线 '__' 前缀的字符串组成。<br>有<br>"add": + 操作。 <br>"sub": - 操作。 其行为类似于 "add" 操作。<br>"mul": * 操作。 其行为类似于 "add" 操作。<br>"div": / 操作。 其行为类似于 "add" 操作。<br>"mod": % 操作。 其行为类似于 "add" 操作，它的原生操作是这样的 o1 - floor(o1/o2)*o2<br>"pow": ^ （幂）操作。 其行为类似于 "add" 操作，它的原生操作是调用 pow 函数（通过 C math 库）。<br>"unm": 一元 - 操作。<br>"concat": .. （连接）操作，<br>"len": # 操作。<br>"eq": == 操作。<br>a ~= b 等价于 not (a == b) 。<br>"lt": &lt; 操作。<br>"le": &lt;= 操作。<br>a &gt;= b 等价于 b &lt;= a 。注意，如果元方法 "le" 没有提供，Lua 就尝试 "lt" ，它假定 a &lt;= b 等价于 not (b &lt; a) <br><br>"index": 取下标操作用于访问 table[key] 。<br>"newindex": 赋值给指定下标 table[key]= value 。<br>"call": 当 Lua 调用一个值时调用。<br><br><br>以上事件中，index 和newindex 很关键，常常被自定义的函数所取代。<br><br>如：定义一个函数取代环境中的处理<br>local f = function (t,i)<br>&nbsp; error("cannot redefine global variable `"..i.."'",2)<br>end<br><br>local g = {}<br>local G = getfenv()<br>setmetatable(g,{__index=G,__newindex=f})<br><br>--设置g的运行环境<br>setfenv(1,g)<br>rawset(g,"x",3)<br><br>x=2<br>y=1 -- cannot redefine 'y'<br><br>以上的替换只能在C下改变，在lua中不能中改变其它任何类型的值的 metatable（debug 库例外）；<br><br>值得说明的是：<br>table 和userdata类型拥有独立的 metatable （也可以共享一个相同的表作它们的 metatable）<br><br>在lua的扩展库函数中有一个<br>luaL_newmetatable<br>这个函数是创建一个表，作为元表提供给userdata使用。<br>(userdata，可以理解为自定义的一个数据结构。)<br><br><br><br><br><br><img src ="http://www.cnitblog.com/kenlistian/aggbug/50403.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/kenlistian/" target="_blank">kenlistian</a> 2008-10-19 14:44 <a href="http://www.cnitblog.com/kenlistian/archive/2008/10/19/50403.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>lua 第三方插件索引</title><link>http://www.cnitblog.com/kenlistian/archive/2008/10/18/50372.html</link><dc:creator>kenlistian</dc:creator><author>kenlistian</author><pubDate>Fri, 17 Oct 2008 16:49:00 GMT</pubDate><guid>http://www.cnitblog.com/kenlistian/archive/2008/10/18/50372.html</guid><wfw:comment>http://www.cnitblog.com/kenlistian/comments/50372.html</wfw:comment><comments>http://www.cnitblog.com/kenlistian/archive/2008/10/18/50372.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/kenlistian/comments/commentRss/50372.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/kenlistian/services/trackbacks/50372.html</trackback:ping><description><![CDATA[&nbsp;下面的这些内容不包含在本文中：<br>官方的Lua包和文档 (参看 <u><span style="color: #800080;"><a  href="http://www.lua.org/%29,%EF%BC%9B%E6%B6%89%E5%8F%8A%E5%88%B0Lua%E4%BD%BF%E7%94%A8%E4%BD%86%E4%B8%8D%E6%98%AF%E8%A2%ABLua%E4%BD%BF%E7%94%A8%E8%80%85%E6%99%AE%E9%81%8D%E4%BD%BF%E7%94%A8%E7%9A%84%E4%B8%9C%E8%A5%BF%20%28%E5%8F%82%E7%9C%8B" target="_blank">http://www.lua.org/</a></span></u>),<span style="color: #000000;">；<br></span>涉及到Lua使用但不是被Lua使用者普遍使用的东西<span style="color: #000000;"> (参看 </span><a  href="http://www.lua.org/uses.html" target="_blank"><u><span style="color: #0000ff;">http://www.lua.org/uses.html</span></u></a><span style="color: #000000;">), </span>；<br>本wiki已经存在的内容(参看 <a  href="http://lua-users.org/wiki/LuaDirectory" target="_blank"><u><span style="color: #0000ff;">LuaDirectory</span></u></a>). <br> <br><font size="5"><strong><a  href="http://lua-users.org/wiki/LibrariesAndBindings" target="_blank"><u><span style="color: #0000ff;">类库和与Lua绑定的资源</span></u></a></strong></font><br> <br><br><a  href="http://lua-users.org/wiki/LibrariesAndBindings" target="_blank"><u><span style="color: #0000ff;">LibrariesAndBindings</span></u></a>&nbsp; <br><font size="5"><strong>开发环境</strong></font><br> <br>
<ul style="margin: 0pt 0pt 0pt 15px;">
    <li><a  href="http://www.gorlice.net.pl/%7Erybak/luaide" target="_blank"><u><span style="color: #0000ff;">[LuaIDE]</span></u></a> (5.0) - Windows平台Lua的整合开发环境(最新发布 2004-01-29). </li>
    <li><a  href="http://www.luascript.thersgb.net/" target="_blank"><u><span style="color: #0000ff;">[wxLua]</span></u></a> (5.0) -&nbsp;Lua and wxWidgets的混合体.有自己的带有调试器的IDE。这个IDE使用wxlua开发的。 </li>
    <li><a  href="http://www.ideais.com.br/luaeclipse/" target="_blank"><u><span style="color: #0000ff;">[LuaEclipse]</span></u></a> (5.0) - Eclipse 平台的Lua IDE . </li>
    <li><a  href="http://www.vortexentertainment.com/produto.php?id=luaide" target="_blank"><u><span style="color: #0000ff;">[Vortex LuaIDE]</span></u></a> (5.0) -&nbsp;Brazilian Portuguese的一些免费的Lua IDE! (Outra IDE para Lua gratuita, mas em Portugu&#234;s!). </li>
    <li><a  href="http://luaforge.net/projects/luax/" target="_blank"><u><span style="color: #0000ff;">[LuaX]</span></u></a> (5.x) - 支持多种操作系统下开发Lua应用的开发平台(with GUI, serial port etc. modules)特别适合于工业自动化和嵌入式产品开发。 </li>
    <li><a  href="http://visualwx.altervista.org/" target="_blank"><u><span style="color: #0000ff;">[VisualWx]</span></u></a> (5.x) -&nbsp;Lua &amp; wxLua的IDE (自由软件) </li>
    <li><a  href="http://www.quotixsoftware.com/qde_index.htm" target="_blank"><u><span style="color: #0000ff;">[QDE]</span></u></a> (5.x) -&nbsp;Lua的Quotix 开发环境. 他支持工程管理，多文档接口等 (最新发布2005-03-06). </li>
    <li><a  href="http://blua.sourceforge.net/" target="_blank"><u><span style="color: #0000ff;">[B:Lua]</span></u></a> -&nbsp;开源项目： 具备各种特征的Lua IDE. </li>
</ul>
<br><font size="5"><strong>代码封装</strong></font><br>
<ul style="margin: 0pt 0pt 0pt 15px;">
    <li><a  href="http://www.thomasandamy.com/projects/CPB/" target="_blank"><u><span style="color: #0000ff;">[CPB]</span></u></a> (5.0)(Win32) - C++&nbsp;和 Lua连接之桥,实现两种语言的相互通信. </li>
    <li><a  href="http://sourceforge.net/projects/calua" target="_blank"><u><span style="color: #0000ff;">[CaLua]</span></u></a> (5.0) - 实现了绑定C函数和结构体到Lua，可以在Lua中使用C指针、数组、函数。(使用x86结构的计算机) </li>
    <li><a  href="http://sourceforge.net/projects/cpplua" target="_blank"><u><span style="color: #0000ff;">[CppLua]</span></u></a> (5.0) - lua API的C++封装。 </li>
    <li><a  href="ftp://ftp.tecgraf.puc-rio.br/pub/lhf/lua2c.tar.gz" target="_blank"><u><span style="color: #0000ff;">[lua2c]</span></u></a> (5.0) - 将Lua代码转换成C代码的工具. </li>
    <li><a  href="http://luabind.sf.net/" target="_blank"><u><span style="color: #0000ff;">[luabind]</span></u></a> (5.0) - 基于模板的，绑定Lua和C++类以及函数 </li>
    <li><a  href="http://www.tecgraf.puc-rio.br/%7Eceles/tolua/" target="_blank"><u><span style="color: #0000ff;">[tolua]</span></u></a> (5.0) - 自动绑定C/C++和Lua的工具. </li>
    <li><a  href="http://lua-users.org/wiki/LuaWrapper" target="_blank"><u><span style="color: #0000ff;">LuaWrapper</span></u></a> 基于模版的封装包，很容易绑定C++代码和Lua。纯头文件。 </li>
    <li><a  href="http://www.codenix.com/%7Etolua" target="_blank"><u><span style="color: #0000ff;">[tolua++]</span></u></a> (5.0) - tolua的高级版本，带有c++面向对象的特征. ( <a  href="http://lua-users.org/wiki/CompilingToluappWithoutScons" target="_blank"><u><span style="color: #0000ff;">CompilingToluappWithoutScons</span></u></a> i.e., Compiling Tolua++ Without SCons ) </li>
    <li><a  href="http://lua-users.org/files/wiki_insecure/users/luapi/" target="_blank"><u><span style="color: #0000ff;">[luapi]</span></u></a> (5.0) - Lua api的C封装. </li>
    <li><a  href="http://rzserv2.fhnon.de/%7Elg016586/PBLua/" target="_blank"><u><span style="color: #0000ff;">[PBLua]</span></u></a> (5.0.2) - Lua 5.0.2基本库的封装. </li>
    <li><a  href="http://mark0.net/code-powerblua-e.html" target="_blank"><u><span style="color: #0000ff;">[PowerBLua]</span></u></a> (5.0) - PowerBASIC include &amp; source for wrapping Lua (work in progress). </li>
    <li><a  href="http://wxcode.sourceforge.net/components/wxscript/index.html" target="_blank"><u><span style="color: #0000ff;">[wxScript]</span></u></a> (5.0.2) - 一些抽象类，添加到脚本解释器可以使你的wxWidgets支持Lua语言。 </li>
    <li><a  href="http://moin.conectiva.com.br/LunaticPython" target="_blank"><u><span style="color: #0000ff;">[LunaticPython]</span></u></a> (0.1) - Lua/Python&nbsp;的双向桥。可以将Lua解释器嵌入到python中，反过来也可以。 </li>
</ul>
<br> <br><font size="5"><strong>Lua的使用</strong></font><br><em>Lua的使用列表<a  href="http://www.lua.org/uses.html" target="_blank"><u><span style="color: #0000ff;">[1]</span></u></a>. </em><br> <br>
<ul style="margin: 0pt 0pt 0pt 15px;">
    <li><a  href="http://premake.sourceforge.net/" target="_blank"><u><span style="color: #0000ff;">[Premake]</span></u></a> -一个用Lua语言实现的 automake 替代品. 可以为MS VC++, GNU make, 等创建工程文件. </li>
    <li><a  href="http://luaforge.net/projects/lumikki" target="_blank"><u><span style="color: #0000ff;">[Lumikki]</span></u></a> (5.0) - 使用Lua宏创建web站点，可以使用导航菜单，风格等。</li>
</ul>
<br><font size="5"><strong>工具</strong></font><br> <br>
<ul style="margin: 0pt 0pt 0pt 15px;">
    <li><a  href="http://lua-users.org/wiki/ExpLua" target="_blank"><u><span style="color: #0000ff;">ExpLua</span></u></a> (5.0) - 代码文档工具(开发中。。。). </li>
    <li><a  href="http://luaforge.net/projects/hamster/" target="_blank"><u><span style="color: #0000ff;">[Hamster (ex SCons/Lua)]</span></u></a> (5.x) - Lua front-end to the SCons build engine (or others). </li>
    <li><a  href="http://www.keplerproject.org/" target="_blank"><u><span style="color: #0000ff;">[Kepler Project]</span></u></a> (5.0) - 使用 <a  href="http://www.keplerproject.org/cgilua/" target="_blank"><u><span style="color: #0000ff;">[CGILua 5.0]</span></u></a>实现的Lua 5.0的web模板引擎&nbsp;. </li>
    <li><a  href="http://www.xtgsystems.com/linux/lua/mod_lua.php" target="_blank"><u><span style="color: #0000ff;">[Mod_Lua (5.0)]</span></u></a> - &nbsp;Apache 2的 module，使得web应用与PHP类似。 </li>
    <li><a  href="http://www.tecgraf.puc-rio.br/%7Elhf/ftp/lua/" target="_blank"><u><span style="color: #0000ff;">[ctrace]</span></u></a> (5.0) - 跟踪Lua API调用的工具. </li>
    <li><a  href="http://www.tecgraf.puc-rio.br/%7Elhf/ftp/lua/" target="_blank"><u><span style="color: #0000ff;">[lper]</span></u></a> (5.0) - 创建持久Lua 状态的工具,&nbsp;基于 <a  href="http://sources.redhat.com/gdb/5/onlinedocs/mmalloc.html" target="_blank"><u><span style="color: #0000ff;">[GNU mmalloc]</span></u></a> (part of GDB). </li>
    <li><a  href="http://lua-users.org/wiki/PlutoLibrary" target="_blank"><u><span style="color: #0000ff;">PlutoLibrary</span></u></a> (5.0.2) - 为Lua创建重量级的持久性. </li>
    <li><a  href="http://luaforge.net/projects/chunkspy/" target="_blank"><u><span style="color: #0000ff;">[ChunkSpy]</span></u></a> (5.0.2) - a binary chunk disassembler, with interactive mode, reading custom binary chunk formats, etc. </li>
    <li><a  href="http://www.geocities.com/f18m_cpp217828/prog/lua_win32.zip" target="_blank"><u><span style="color: #0000ff;">[lua bakefile]</span></u></a> (5.0.2) -&nbsp;创建 LUA&nbsp;工程的makefile和工程文件。 </li>
    <li><a  href="http://www.geocities.com/f18m_cpp217828/prog/tolua_win32.zip" target="_blank"><u><span style="color: #0000ff;">[tolua bakefile]</span></u></a> (5.0.2) - 创建 TOLUA&nbsp;工程的makefile和工程文件。 </li>
    <li><a  href="http://luaforge.net/projects/chunkbake/" target="_blank"><u><span style="color: #0000ff;">[ChunkBake]</span></u></a> (5.0.2) - a line-oriented assembler for Lua 5 virtual machine instructions </li>
    <li><a  href="http://luaforge.net/projects/luasrcdiet/" target="_blank"><u><span style="color: #0000ff;">[LuaSrcDiet]</span></u></a> (5.0.2) - 通过删除不必要的空白和注释缩减Lua文件的大小。 </li>
    <li><a  href="http://www.keplerproject.org/luaprofiler" target="_blank"><u><span style="color: #0000ff;">[LuaProfiler]</span></u></a> (5.0) - 一个用来查找Lua应用瓶颈的工具time profiler 。</li>
</ul>
<br><br>See also <a  href="http://lua-users.org/wiki/LuaEditorSupport" target="_blank"><u><span style="color: #0000ff;">LuaEditorSupport</span></u></a>.&nbsp; <br><font size="5"><strong>文档</strong></font><br> <br>
<ul style="margin: 0pt 0pt 0pt 15px;">
    <li><a  href="http://lua.riscos.org.uk/Guide/" target="_blank"><u><span style="color: #0000ff;">[介绍性的指导]</span></u></a> (5.0) - Lua 5.0 的介绍教程- 基于 Joe Taylor的评论. ( Try <a  href="http://lua.riscos.org.uk/" target="_blank"><u><span style="color: #0000ff;">http://lua.riscos.org.uk/</span></u></a> ) </li>
    <li><a  href="http://lua-users.org/files/wiki_insecure/users/lcandido/lua5.0man_webbook.zip" target="_blank"><u><span style="color: #0000ff;">[Lua&nbsp;5手册&nbsp;(webbook)]</span></u></a> (5.0) -&nbsp; webbook格式的Lua 5.0手册。 </li>
    <li><a  href="http://lua-users.org/wiki/LuaShortReference" target="_blank"><u><span style="color: #0000ff;">Lua简短参考</span></u></a> </li>
    <li><u><span style="color: #800080;">Lua教程</span></u> </li>
    <li><a  href="http://luaforge.net/docman/?group_id=80" target="_blank"><u><span style="color: #0000ff;">[Lua 5 快速参考]</span></u></a> (5.0) - Lua 5.0的小参考手册(PDF)，包含彩色导航栏。&nbsp; </li>
    <li><a  href="http://luaforge.net/docman/?group_id=83" target="_blank"><u><span style="color: #0000ff;">[Lua 5 虚拟机指令介绍]</span></u></a> (5.0) - SXW和PDF格式。 </li>
    <li><a  href="http://lua-users.org/wiki/LuaHelp" target="_blank"><u><span style="color: #0000ff;">Lua帮助</span></u></a>, 方便在Lua手册中查找信息，类似Unix的man页面。</li>
</ul>
<br> <br><font size="5"><strong>发布版</strong></font><br>See <a  href="http://lua-users.org/wiki/LuaBinaries" target="_blank"><u><span style="color: #0000ff;">LuaBinaries</span></u></a>for
links to precompiled vanilla Lua 5.0 executables for variousplatforms.
Real binaries (without addons) should move from here tothere. <br> <br>
<ul style="margin: 0pt 0pt 0pt 15px;">
    <li><a  href="http://luacheia.lua-users.org/" target="_blank"><u><span style="color: #0000ff;">[LuaCheia]</span></u></a> (5.0) - Lua 5.0 for GNU/Linux, Mac/OS X, Windows, *BSD, Solaris, etc. Includes many add-on binary modules. </li>
    <li><a  href="http://luaplus.org/tiki-index.php" target="_blank"><u><span style="color: #0000ff;">[LuaPlus]</span></u></a> (5.0) - C++ enhancements and various extensions to core Lua functionality </li>
    <li><a  href="http://gwpr03.microlink.com.br/%7Eacosta/lua/" target="_blank"><u><span style="color: #0000ff;">[Linux RPMs]</span></u></a> (5.0) - i386 binary, source and spec file for Lua 5.0.2 </li>
    <li><a  href="http://rpmfind.net/linux/rpm2html/search.php?query=lua" target="_blank"><u><span style="color: #0000ff;">[RPMs for Lua]</span></u></a> (5.0) - from Rpmfind.Net. </li>
    <li><a  href="http://lsp2html.sourceforge.net/luarpms/" target="_blank"><u><span style="color: #0000ff;">[RPMs with Lua modules]</span></u></a> </li>
    <li><a  href="http://www.freepoc.org/viewapp.php?id=32" target="_blank"><u><span style="color: #0000ff;">[Lua 5 for EPOC]</span></u></a> (5.0) - Lua 5.0.1 for Symbian OS v1-5. </li>
    <li><a  href="http://www.inf.puc-rio.br/%7Emiller/luace" target="_blank"><u><span style="color: #0000ff;">[LuaCE]</span></u></a> (5.0) - additional source files for compiling Lua for Windows CE. </li>
    <li><a  href="http://www.uoam.net/lua.html" target="_blank"><u><span style="color: #0000ff;">[LuaPPC]</span></u></a> (5.0) - Stand-alone Lua 5.0 interpreter for the Pocket PC. (Built using LuaCE above.) </li>
    <li><a  href="http://luaforge.net/projects/luapocket/" target="_blank"><u><span style="color: #0000ff;">[LuaPocket]</span></u></a> (5.0) - Stand-alone Lua 5.0 interpreter for the Pocket PC with graphic support. (Built using LuaPPC above.) </li>
    <li><a  href="http://lua.riscos.org.uk/" target="_blank"><u><span style="color: #0000ff;">[Lua for RISC OS]</span></u></a> (5.0) </li>
    <li><a  href="http://sourceforge.net/projects/luapalmos/" target="_blank"><u><span style="color: #0000ff;">[Lua for Palm OS]</span></u></a> (5.0) Port of Lua for Palm (in alpha). </li>
    <li><a  href="http://lekernel.lya-fr.com/lua.html" target="_blank"><u><span style="color: #0000ff;">[Lua89]</span></u></a> (5.0) Experimental port of Lua to the TI89 graphing calculator. </li>
</ul>
<br><font size="5"><strong>其他的一些Lua实现方式</strong></font><br> <br>
<ul style="margin: 0pt 0pt 0pt 15px;">
    <li><a  href="http://www.goron.de/%7Efroese/sol/" target="_blank"><u><span style="color: #0000ff;">[Sol]</span></u></a> - Lua 的派生物. </li>
    <li><a  href="http://www.tecgraf.puc-rio.br/%7Ercerq/luadotnet/" target="_blank"><u><span style="color: #0000ff;">[Lua.NET]</span></u></a> .net相关的Lua </li>
    <li><a  href="http://www.dis.uniroma1.it/pub/demetres/LeonardoPrograms/lua.sit.bin" target="_blank"><u><span style="color: #0000ff;">[LuaLeo]</span></u></a> -&nbsp; 根据<a  href="http://www.dis.uniroma1.it/%7Edemetres/Leonardo/" target="_blank"><u><span style="color: #0000ff;">[Leonardo VM]</span></u></a> 实现的Lua 3.1 </li>
    <li><a  href="http://www.cminusminus.org/code.html#luaml" target="_blank"><u><span style="color: #0000ff;">[Lua-ML]</span></u></a> -&nbsp; 由面向对象的Caml实现的 Lua 2.5 </li>
    <li><a  href="http://www.yindo.com/?from=steve" target="_blank"><u><span style="color: #0000ff;">[Yindo]</span></u></a> - Lua 的实现，作为OpenGL 浏览器插件(很快过时了) </li>
    <li><a  href="http://luaforge.net/projects/yueliang/" target="_blank"><u><span style="color: #0000ff;">[Yueliang]</span></u></a> (5.0.2) - 使用Lua实现Lua，包括词法解析、语法解析、代码生成和生成二进制chunks.</li>
</ul><img src ="http://www.cnitblog.com/kenlistian/aggbug/50372.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/kenlistian/" target="_blank">kenlistian</a> 2008-10-18 00:49 <a href="http://www.cnitblog.com/kenlistian/archive/2008/10/18/50372.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>lua中字符串匹配笔记</title><link>http://www.cnitblog.com/kenlistian/archive/2008/10/15/50292.html</link><dc:creator>kenlistian</dc:creator><author>kenlistian</author><pubDate>Wed, 15 Oct 2008 14:12:00 GMT</pubDate><guid>http://www.cnitblog.com/kenlistian/archive/2008/10/15/50292.html</guid><wfw:comment>http://www.cnitblog.com/kenlistian/comments/50292.html</wfw:comment><comments>http://www.cnitblog.com/kenlistian/archive/2008/10/15/50292.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/kenlistian/comments/commentRss/50292.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/kenlistian/services/trackbacks/50292.html</trackback:ping><description><![CDATA[&nbsp;<br><br><br>string.gsub 函数有三个参数：目标串，模式串，替换串。<br>基本作用是用来查找匹配模式的串，并将使用替换串其替换掉： <br><br>s = string.gsub("Lua is good", "good", "bad?") <br>print(s)&nbsp;&nbsp; --&gt; Lua is bad<br><br>string.gsub 的第二个返回值表示进行替换操作的次数。例如，<br>下面代码计字符串中空格出现的次数： <br><br>_, count = string.gsub("test test", " ", " ") <br>_ 表示哑元变量<br><br>模式串<br>.&nbsp;&nbsp; 任意字符 <br>%a&nbsp;&nbsp; 字母 <br>%c&nbsp;&nbsp; 控制字符 <br>%d&nbsp;&nbsp; 数字 <br>%l&nbsp;&nbsp; 小写字母 <br>%p&nbsp;&nbsp; 标点字符 <br>%s&nbsp;&nbsp; 空白符 <br>%u&nbsp;&nbsp; 大写字母 <br>%w&nbsp;&nbsp; 字母和数字 <br>%x&nbsp;&nbsp; 十六进制数字 <br>%z&nbsp;&nbsp; 代表 0的字符 <br><br><br>特殊字符如下：<br>(). % + - * ? [ ^ $ <br>% 也作为以上特殊字符的转义字符。<br><br>[] 该方框作为匹配该范围的集合，。<br>&nbsp; 如[0-9] 则匹配0到9的数字范围<br><br>Lua 中的模式修饰符有四个： <br>+&nbsp;&nbsp; 匹配前一字符 1 次或多次，最长匹配<br>*&nbsp;&nbsp; 匹配前一字符 0 次或多次，最长匹配<br>-&nbsp;&nbsp; 匹配前一字符 0 次或多次，最短匹配<br>?&nbsp;&nbsp; 匹配前一字符 0 次或 1次 <br>'+'，匹配一个或多个字符，总是进行最长的匹配。<br>如，模式&nbsp; '%a+'&nbsp; 匹配一个或多个字母或者一个单词： <br><br>注意以上的区别：<br><br>如：匹配c中的注释串<br>用 '/%*.*%*/'&nbsp; 和'/%*.-%*/'<br><br>str = "int x; /* x */&nbsp; int y; /* y */" <br>print(string.gsub(str, "/%*.*%*/", "&lt;注释串&gt;")) <br>&nbsp; --&gt; int x; &lt;注释串&gt; <br>采用 '.-' 则为最短匹配，即匹配 "/*" 开始到第一个 "*/"&nbsp; 之前的部分： <br>str = "int x; /* x */&nbsp; int y; /* y */" <br>print(string.gsub(str, "/%*.-%*/", "&lt;注释部分&gt;")) <br>&nbsp; --&gt; int x; &lt;注释串&gt;&nbsp; int y; &lt;注释串&gt; <br><br>以 '^'&nbsp; 开头表示只匹配目标串的开始部分，<br>以 '$'&nbsp; 结尾表示只匹配目标串的结尾部分。<br><br>%b 表示匹配对称字符，注意其只能针对的ansi码单字符。<br>x = string.gsub("xdddddyxxx", "%bxy", "取代")<br>print(x)&nbsp;&nbsp; --&gt;取代xxx<br><br>如去除字符串首尾的空格： <br>function trim (s) <br>&nbsp; return (string.gsub(s, "^%s*(.-)%s*$", "%1")) <br>end <br><br><br>---------------------------------<br><br>看原文中的gsub注释：相当详细，不过对于模式解释补充在上。<br><br>string.gsub (s, pattern, repl [, n])<br><br>Returns a copy of s in which all occurrences of the pattern <br>have been replaced by a replacement string specified by repl,<br>which may be a string, a table, or a function. <br>gsub also returns, as its second value, the total number of substitutions made.<br><br>repl是字符串，则为替换。 如果在参数前有%则表示符合匹配的字符串<br>If repl is a string, then its value is used for replacement. <br>The character % works as an escape character:<br>any sequence in repl of the form %n, with n between 1 and 9, stands for the <br>value of the n-th captured substring (see below). <br>The sequence %0 stands for the whole match. The sequence %% stands for a single %.<br><br><br>repl作为表参数<br>If repl is a table, then the table is queried for every match, <br>using the first capture as the key; if the pattern specifies <br>no captures, then the whole match is used as the key.<br><br>如果参数为函数，则每次匹配成功则调用该函数<br>If repl is a function, then this function is called every <br>time a match occurs, with all captured substrings passed <br>as arguments, in order; <br><br>if the pattern specifies no captures,<br>then the whole match is passed as a sole argument.<br><br>If the value returned by the table query or by the function call is a string or a number, <br>then it is used as the replacement string; otherwise, if it is false or nil, <br>then there is no replacement (that is, the original match is kept in the string).<br><br>参数n则限制最大<br>The optional last parameter n limits the maximum number of substitutions to occur.<br><br><br>举例：<br>&nbsp;&nbsp; %1 表示符合模式的第一个匹配<br>&nbsp;&nbsp; x = string.gsub("hello world", "(%w+)", "%1 %1")<br>&nbsp;&nbsp; --&gt; x="hello hello world world"<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; 第4项<br>&nbsp;&nbsp; x = string.gsub("hello world", "%w+", "%0 %0", 1)<br>&nbsp;&nbsp; --&gt; x="hello hello world"<br>&nbsp;&nbsp; <br>&nbsp;&nbsp; hello 和from作为模式中左匹配为%1，world 和lua为右匹配，为%2<br>&nbsp;&nbsp; x = string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1")<br>&nbsp;&nbsp; --&gt; x="world hello Lua from"<br><br>&nbsp;&nbsp; 替换 以$打头的字符串<br>&nbsp;&nbsp; x = string.gsub("home = $HOME, user = $USER", "%$(%w+)", os.getenv)<br>&nbsp;&nbsp; --&gt; x="home = /home/roberto, user = roberto"<br>&nbsp;&nbsp; <br>&nbsp;&nbsp; 参数为函数类型<br>&nbsp;&nbsp; x = string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return loadstring(s)()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end)<br>&nbsp;&nbsp;&nbsp;&nbsp; --&gt; x="4+5 = 9"<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; 参数为表类型<br>&nbsp;&nbsp; local t = {name="lua", version="5.1"}<br>&nbsp;&nbsp; x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t)<br>&nbsp;&nbsp; --&gt; x="lua-5.1.tar.gz"<br><br>==============================<br>gmatch 的用法：<br>在模式符合匹配多次时<br>Returns an iterator function that, each time it is called,<br>returns the next captures from pattern over string s. <br>If pattern specifies no captures, then the whole match <br>is produced in each call.<br><br>看例子：<br>&nbsp;&nbsp; s = "hello world from Lua"<br>&nbsp;&nbsp; for w in string.gmatch(s, "%a+") do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(w)<br>&nbsp;&nbsp; end<br>&nbsp; <br>采用gmatch来解析到表类型<br>&nbsp;&nbsp;&nbsp;&nbsp; t = {}<br>&nbsp;&nbsp;&nbsp;&nbsp; s = "from=world, to=Lua"<br>&nbsp;&nbsp;&nbsp;&nbsp; for k, v in string.gmatch(s, "(%w+)=(%w+)") do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t[k] = v<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>一个http传送参数的应用<br>URL 编码,<br>这种编码将一些特殊字符（比&nbsp; '=' '&amp;' '+'）转换为"%XX"形式的编码，<br>XX是字符的16进制表示，空白为'+'。<br>如，将"a+b = c"&nbsp; 编码为 "a%2Bb+%3D+c" <br>一个典型的参数串：<br>name=al&amp;query=a%2Bb+%3D+c&amp;q=yes+or+no <br><br>1先把空格和16进制编码转换为ansi码<br>function convet1(s) <br>&nbsp; s = string.gsub(s, "+", " ") <br>&nbsp; s = string.gsub(s, "%%(%x%x)", function (h) <br>&nbsp;&nbsp; return string.char(tonumber(h, 16)) <br>&nbsp; end) <br>&nbsp; return s <br>end <br><br>2.解析参数串<br>p = {} <br>function decode (s) <br>&nbsp; for name, value in string.gmatch(s, "([^&amp;=]+)=([^&amp;=]+)") do <br>&nbsp; name = unescape(name) <br>&nbsp; value = unescape(value) <br>&nbsp; p[name] = value <br>&nbsp; end <br>end <br><br><br><img src ="http://www.cnitblog.com/kenlistian/aggbug/50292.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/kenlistian/" target="_blank">kenlistian</a> 2008-10-15 22:12 <a href="http://www.cnitblog.com/kenlistian/archive/2008/10/15/50292.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>lua 协同基本</title><link>http://www.cnitblog.com/kenlistian/archive/2008/10/15/50251.html</link><dc:creator>kenlistian</dc:creator><author>kenlistian</author><pubDate>Wed, 15 Oct 2008 04:43:00 GMT</pubDate><guid>http://www.cnitblog.com/kenlistian/archive/2008/10/15/50251.html</guid><wfw:comment>http://www.cnitblog.com/kenlistian/comments/50251.html</wfw:comment><comments>http://www.cnitblog.com/kenlistian/archive/2008/10/15/50251.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/kenlistian/comments/commentRss/50251.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/kenlistian/services/trackbacks/50251.html</trackback:ping><description><![CDATA[Lua 通过 table 提供了所有的协同函数，<br>create 函数创建一个新的协同程序，<br>create只有一个参数：<br>协同程序将要运行的代码封装而成的函数，返回值为thread类型的值。<br><br>通常情况下 create 的参数是一个匿名&nbsp; <br>co = coroutine.create(function () <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print("hello") <br>&nbsp;&nbsp;&nbsp;&nbsp; end) <br><br>print(co)&nbsp;&nbsp; --&gt; thread: 0x8071d98 <br><br>协同有三个状态：挂起态，运行态，停止态。<br><br>当创建协同程序时开始状态为挂起态，即创建后不会自动运行，<br>用status 函数检查协同的状态： <br><br>如：<br>print(coroutine.status(co))&nbsp;&nbsp; --&gt; suspended <br><br>挂起状态变为运行态：coroutine.resume <br><br>coroutine.resume(co)&nbsp;&nbsp;&nbsp;&nbsp; --&gt; hello<br><br>这个例子中，协同体打印出"hello"之后便进入终止状态： <br>print(coroutine.status(co))&nbsp;&nbsp; --&gt; dead <br><br>挂起函数yield 。将正在运行的代码挂起，<br><br>如下代码：<br>co = coroutine.create(function () <br>&nbsp;&nbsp;&nbsp; for i=1,10 do <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print("co", i) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; coroutine.yield() <br>&nbsp;&nbsp;&nbsp; end <br>&nbsp; end) <br>&nbsp;<br>运行如下，将在第一个 yield 处被挂起： <br>coroutine.resume(co)&nbsp;&nbsp;&nbsp;&nbsp; --&gt; co&nbsp;&nbsp; 1 <br>print(coroutine.status(co))&nbsp;&nbsp; --&gt; suspended <br>从协同的观点看：使用函数 yield 可以使程序挂起,当激活被挂起的程序时，<br>yield返回并继续程序的执行直到再次遇到 yield 或者程序结束&nbsp; <br>coroutine.resume(co)&nbsp;&nbsp; --&gt; co&nbsp;&nbsp; 2 <br>coroutine.resume(co)&nbsp;&nbsp; --&gt; co&nbsp;&nbsp; 3 <br>... <br>coroutine.resume(co)&nbsp;&nbsp; --&gt; co&nbsp;&nbsp; 10 <br>coroutine.resume(co)&nbsp;&nbsp; -- prints nothing&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br><br><br><img src ="http://www.cnitblog.com/kenlistian/aggbug/50251.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/kenlistian/" target="_blank">kenlistian</a> 2008-10-15 12:43 <a href="http://www.cnitblog.com/kenlistian/archive/2008/10/15/50251.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>lua交互为何用堆栈？</title><link>http://www.cnitblog.com/kenlistian/archive/2008/09/29/49633.html</link><dc:creator>kenlistian</dc:creator><author>kenlistian</author><pubDate>Mon, 29 Sep 2008 03:25:00 GMT</pubDate><guid>http://www.cnitblog.com/kenlistian/archive/2008/09/29/49633.html</guid><wfw:comment>http://www.cnitblog.com/kenlistian/comments/49633.html</wfw:comment><comments>http://www.cnitblog.com/kenlistian/archive/2008/09/29/49633.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/kenlistian/comments/commentRss/49633.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/kenlistian/services/trackbacks/49633.html</trackback:ping><description><![CDATA[为何起用lua堆栈<br><br>当在Lua和C之间交换数据时我们面临着两个问题：<br>动态与静态类型系统的不匹配和自动与手动内存管理的不一致。<br><br>在Lua中，我们写下a[k]=v时，k和v可以有几种不同的类型（由于metatables的存在，a也可能有不同的类型）。<br><br>如果我们想在C中提供类似的操作，无论怎样，操作表的函数(settable)必定有一个固定的类型。<br>我们将需要几十个不同的函数来完成这一个的操作（三个参数的类型的每一种组合都需要一个函数）。<br><br>在C中声明一些union类型来解决这个问题，称之为lua_Value，它能够描述所有类型的Lua值。<br>，就可以这样声明settable<br>void lua_settable (lua_Value a, lua_Value k, lua_Value v);<br>这个解决方案有两个缺点。<br>1。要将如此复杂的类型映射到其它语言可能很困难；Lua不仅被设计为与C/C++易于交互，<br>&nbsp; Java,Fortran以及类似的语言也一样。<br>2。Lua负责垃圾回收：如果将Lua值保存在C变量中，Lua引擎没有办法了解这种用法；<br>&nbsp;&nbsp; 它可能错误地认为某个值为垃圾并收集他。<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>Lua API没有定义任何类似lua_Value的类型。替代的方案，<br>它用一个抽象的栈在Lua与C之间交换值。<br>栈中的每一条记录都可以保存任何Lua值。<br><br>无论你何时想要从Lua请求一个值（比如一个全局变量的值），<br>1.将这个值压入栈，<br>2。调用Lua（这个值将被弹出）。<br><br>仍然需要一个不同的函数将每种C类型压入栈和一个不同函数从栈上取值（译注：只是取出不是弹出），<br>但是我们避免了组合式的爆炸（combinatorial explosion）。另外，因为栈是由Lua来管理的，<br>垃圾回收器知道那个值正在被C使用。几乎所有的API函数都用到了栈。<br><br>lua_pcall从栈上获取要被调用的函数并把任何临时的错误信息放在这里。<br>Lua以一个严格的LIFO规则（后进先出；也就是，始终存取栈顶）来操作栈。<br><br>当你调用Lua时，它只会改变栈顶部分。你的Ｃ代码却有更多的自由；更明确的来讲，<br>你可以查询栈上的任何元素，甚至是在任何一个位置插入和删除元素。<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <br>API有一系列压栈的函数，它将每种可以用C来描述的Lua类型压栈：<br>空值（nil）&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 用lua_pushnil，<br>数值型（doubele）&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 用lua_pushnumber，<br>布尔型（在C中用整数表示）&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 用lua_pushboolean，<br>任意的字符串（char*类型，允许包含'\0'字符）&nbsp;&nbsp; 用lua_pushlstring，<br>C语言风格（以'\0'结束）的字符串（const char*）用lua_pushstring：<br><br>void lua_pushnil (lua_State *L);<br>void lua_pushboolean (lua_State *L, int bool);<br>void lua_pushnumber (lua_State *L, double n);<br>void lua_pushlstring (lua_State *L, const char *s,size_t length);<br>void lua_pushstring (lua_State *L, const char *s);<br><br>同样也有将C函数和userdata值压入栈的函数，稍后会讨论到它们。<br>Lua中的字符串不是以零为结束符的；它们依赖于一个明确的长度，<br>因此可以包含任意的二进制数据。<br><br>将字符串压入串的正式函数是lua_pushlstring，它要求一个明确的长度作为参数。<br>对于以零结束的字符串，你可以用lua_pushstring（它用strlen来计算字符串长度）。<br><br>Lua是拷贝字符串而不是保持指向外部字符串（或任何其它对象，除了C函数——它总是静态指针）的指针。<br>对于它保持的所有字符串，Lua要么做一份内部的拷贝要么重新利用已经存在的字符串。<br><br>检测栈上是否有足够你需要的空间<br>int lua_checkstack (lua_State *L, int sz);<br><br><br>查询元素<br>&nbsp; API用索引来访问栈中的元素。<br>&nbsp; <br>&nbsp; 在栈中的第一个元素（也就是第一个被压入栈的）有索引1，下一个有索引2，以此类推。<br>&nbsp; 我们也可以用栈顶作为参照来存取元素，利用负索引。<br>&nbsp; 在这种情况下，-1指出栈顶元素（也就是最后被压入的），-2指出它的前一个元素，以此类推。<br>&nbsp; <br>&nbsp; 如，调用lua_tostring(L, -1)以字符串的形式返回栈顶的值。<br>&nbsp; <br>&nbsp; 在某些场合使用正索引访问栈较方便，另外一些情况下，使用负索引访问栈更方便。<br><br>API提供了一套lua_is*函数来检查一个元素是否是一个指定的类型，*可以是任何Lua类型。<br>因此有lua_isnumber,lua_isstring,lua_istable以及类似的函数。所有这些函数都有同样<br>的原型：<br><br>int lua_is... (lua_State *L, int index);<br>lua_isnumber和lua_isstring函数不检查这个值是否是指定的类型，而是看它是否能被转<br>换成指定的那种类型。例如，任何数字类型都满足lua_isstring。<br>还有一个lua_type函数，它返回栈中元素的类型。<br>（lua_is*中的有些函数实际上是用了这个函数定义的宏）<br><br>为了从栈中获得值，这里有lua_to*函数：<br>int lua_toboolean (lua_State *L, int index);<br>double lua_tonumber (lua_State *L, int index);<br>const char * lua_tostring (lua_State *L, int index);<br>size_t lua_strlen (lua_State *L, int index);<br>即使给定的元素的类型不正确，调用上面这些函数也没有什么问题。在这种情况下，<br>lua_toboolean、lua_tonumber和lua_strlen返回0，其他函数返回NULL。<br><br>由于ANSI C没有提供有效的可以用来判断错误发生数字值，所以返回的0是没有什么用处的。<br>对于其他函数而言，我们一般不需要使用对应的lua_is*函数：我们只需要调用lua_is*，<br>测试返回结果是否为NULL即可。<br><br>//返回的是一个指针，则需要另外找个地址拷贝值。。。。。<br>Lua_tostring函数返回一个指向字符串的内部拷贝的指针。你不能修改它（使你想起那里有一个const）。<br>只要这个指针对应的值还在栈内，Lua会保证这个指针一直有效。<br><br>当一个C函数返回后，Lua会清理他的栈，所以，有一个原则：永远不要将指向Lua字符串的指针<br>保存到访问他们的外部函数中。<br><br>Lua_string返回的字符串结尾总会有一个字符结束标志0，但是字符串中间也可能包含0，<br>lua_strlen返回字符串的实际长度。特殊情况下，假定栈顶的值是一个字符串，<br><br>下面的断言(assert)总是有效的：<br><br>//s是一个指向某个字符串地址的指针<br>const char *s = lua_tostring(L, -1); // any Lua string <br>size_t l = lua_strlen(L, -1);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // its length <br>assert(s[l] == '\0');<br>assert(strlen(s) &lt;= l);<br><br><br><br><img src ="http://www.cnitblog.com/kenlistian/aggbug/49633.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/kenlistian/" target="_blank">kenlistian</a> 2008-09-29 11:25 <a href="http://www.cnitblog.com/kenlistian/archive/2008/09/29/49633.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>兵棋概念</title><link>http://www.cnitblog.com/kenlistian/archive/2008/05/19/43896.html</link><dc:creator>kenlistian</dc:creator><author>kenlistian</author><pubDate>Mon, 19 May 2008 09:38:00 GMT</pubDate><guid>http://www.cnitblog.com/kenlistian/archive/2008/05/19/43896.html</guid><wfw:comment>http://www.cnitblog.com/kenlistian/comments/43896.html</wfw:comment><comments>http://www.cnitblog.com/kenlistian/archive/2008/05/19/43896.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/kenlistian/comments/commentRss/43896.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/kenlistian/services/trackbacks/43896.html</trackback:ping><description><![CDATA[一、基础知识 <br>战棋游戏现在已经是我们相当常见的一种游戏方式了，在国际上最有知明度的当属SSI的元帅系列，<br>（《魔幻元帅》、《星际元帅》、《装甲元帅》、《太平洋元帅》、《人民元帅》）其次还有诸如<br>MICPROSE的《幽浮》系列和最老资格的《鱼叉》系列。（其他与军事无关的所谓战棋游戏这里不讨<br>论）<br><br><br>而在国内方面，比较之名的战棋游戏就更多了，限于篇幅，不一一列举。<br><br>战棋游戏的游戏方式和下陆战棋差不多，同样是双方你一回合我一回合一下走一步，<br>所不同的是陆战棋所比的是单纯的官大官小，官小的立马出局，而战棋游戏则不同，<br>你需要考虑各种方面的情况，比如自然、天气（这两项多见于欧美战棋游戏）等级等等，<br>这项我们在后面的战棋环境在说。我们可以施法，人物也可以成长，这也算是战棋游戏最<br>大的特色了。<br><br>附：战棋游戏的规则：<br><br>在一幅地图上，双方各执一方，由甲方先走，甲方可以考虑在可移动范围内移动，移动完毕后<br>可以考虑是否攻击，完后休息待命，轮到乙方行动，这时候乙方也可以先行走，然后在攻击，<br>接下来，乙方也待命，轮到甲方走。如此这般。这就形成了战棋游戏的基本规则。<br><br><br>二、什么叫战棋 <br>其实战棋最早不叫战棋，而是叫兵棋，英文名WAR　GAME，就是战争游戏的意思，多年来，<br>国内一直翻译其为作战模拟，也许是想将其与计算机作战模拟连接起来，但是对理论性、<br>系统性的刻意追求，却间接的导致了许多我军许多官兵听其高深的名字望而生畏，从而放<br>弃对其的研究.....<br><br>无论是说戚继光当年在马背上默弈，还是陈老总在准海战役的前线下棋，说来说去总是为了说兵，<br>而并非说棋，这棋似乎总是兵的陪衬，或者是为了说说棋，而拿兵来虚张一下声势，在国人眼里，<br>兵与棋是有一定的共通之处，但是他毕竟不是一路呀。<br><br>然而在地球的那一边，却上演了一出用兵必下棋，下棋再用兵，兵、棋形影不离，二者融为一体<br>的的活话剧，<br><br><br>三、最早的战棋 <br>现代类型的战棋是由普鲁士的宫庭战争顾问冯.莱斯维茨于1811年年首先发明的，<br>它由一幅地图，一套代表军队的硬方块，一本详细规则　，一张概率表和一个骰子<br>组成，用这套战棋，可以逼真地淙当时战场擤的实际作战活动，所以它一问世，就受<br>到各列强军队的欢迎，被迅速普及和不断加以改进，在第一次和第二次世界大战中，<br>各发达国家用兵棋模拟的方法来试验和检验作战计划已达到了相当水平，其中，下兵<br>棋已列为德军各级指挥机关制定作战计划的正规程序。<br>例如：1939年12月，在德军总部的作战室里，由所有执行进攻法国作战计划的部队指挥<br>官，对通过阿登森林突破马其诺防线的计划用战棋做了实验，棋盘上的预演证明了该计<br>划是可行的，于是付诸战场后，果然取得了巨大的胜利。<br>1940年，尝到了战棋甜头的德军指挥官再次在棋盘上试验了入侵英国的&#8220;海狮计划&#8221;。<br>通过战棋，暴出许多问题，结果这个计划没有实施。<br><br>同年8月，德军总部又用战棋检验了进攻苏联的巴巴罗萨计划，战棋表明基本可行，<br>但是仅从北翼包抄第聂伯河以西的苏军是十分困难的，后来在实上，这一方向的德<br>军陷入了泥沼而导致伤亡惨重。<br><br>1944年11月2日，德国A集团军司令莫德尔正在作战室里进行战棋模拟，前线突然传来战报：<br>一个美军新的危胁出现在赫登－－哥梅特地区，莫德尔将这一情况加入棋局后，棋盘上的推<br>演预示几小时后德军第116装甲师将处于被动地位，该师师长冯.范登堡当即在棋桌边给他的<br>下属下达了作战命令，使部队独占先机，避免了损失。<br>不仅是德国陆军，德国海军也非常重视战棋的作用，1938－－1939年冬天，卡尔.邓尼茨海军<br>上将通过战棋进行模拟，结果发明了著名的潜艇打击盟军护卫舰队的&#8220;狼群战术&#8221;。<br><br>而日本也同样重视战棋的发展，1941年9月2日至13日，日本海军军事学院和陆军军事学院的<br>兵棋预设，分析了偷袭珍珠港的计划，计划表明基本可行，但鱼雷机需要加大打击效力，于<br>是日本海军立即根据此改变了自己的计划，从而使得美军的太平洋舰队受到了重创。而在随<br>后的1942年等等几年中，日本又利用战棋模拟，检验了空袭澳大利亚的西南部、攻占约翰森<br>群岛、夏威夷岛的计划。在一连串的检验中，只有中途岛海战的计划没有成功，当时按照战<br>棋的预演表明，南云的航空母航将受到美军陆基空军的空袭，被击中九次，赤诚和嘉赫两艘<br>航母当即沉灭，但是这次指导战棋预演的最高指挥官官宇垣抗议裁决，将击中次数改为三，<br>航母沉灭数减为一，结果在实战当中，日军四艘航母全部沉灭，日本海军也从此走像了衰亡。<br><br>而英国人在二次世界大战的时候也使用了战棋，当时的陆军中将蒙哥马利将军在对付德军非洲<br>军团的北非战役时，时常将战棋拿出来预设一番，他让参谋以敌人的身份拿起一个标志物向他<br>发起进攻，模拟出&#8220;沙漠之狐&#8221;隆美尔的一个又一个可能的行动，从而使英军获得了后来阿拉<br>曼战役的成功，击败了隆美尔的非洲兵团。<br><br>而在1944年3月7日，在伦敦对保罗学校的地板上，蒙哥马利铺开了一幅大的海滩地图，像艾森毫<br>威尔和邱吉尔讲解他的战棋预演结果，这一战棋结果模拟的不是别的战役，就是日后盟军击败德<br>军取得决定性胜利的诺曼底登陆。<br><br>以上只是最基本的战棋，换句话说，他们或许不能称这之为战棋，只能称之为兵棋，因为他们没<br>有现代战棋游戏所拥有的一些其他东西，真正将兵棋转换成战棋的还是美军。<br><br>那是二次世界大战时期，当时美国海军部成立了一个以著名发明家爱迪生为领导的海军研究实验室，<br>1942年3月1日，由约翰生领导的运筹小组诞生，珍珠港遭袭击后，美军决定对日军展开水雷战，该组<br>反复在棋盘上操作进行双方的扫雷布雷战，使战棋布局不断演化出天气、经济、战略、战术等等对战<br>争的影响，约翰生也因此被美军委派制订作战计划，他在后来的作战报告中写到：&#8220;我发现，日军用<br>来对付强大的水雷攻击的手段，几乎都在每个战棋棋局中出现过。&#8221;最后，日军 670艘舰船被水雷击<br>沉的事例说明了约翰生战略的成功。 <br><br>4、战棋的规格 <br>是什么使战棋游戏有了未卜先知的能力呢？<br>答日：数学。马克思说过：&#8220;理论　只有在能够使用数学语言加以描述时，它才真正升为科学。<br><br>战争理论以及整个军事科学也不例外，数学更深刻的把握住了战争逻辑，将兵棋的整个模拟过程量化了，<br>从而使战棋模拟与一般性的沙盘作业和图上推演完全区别开来。<br><br>尽管战场因素错综复杂， 是一个充满偶然性的领域，但它也与世间的一切事物一样，可以被分解成一些<br>个体和单方面分别加以认识，然后再按照个体和单个方面之间的联系规律，把局部的认识综合起来，就<br>能够把握整个作战过程的总体规律，现代战棋游戏正是按这一思路设计的。一副模拟现代空地一体战的<br>战棋，地图为 256＊256，首先规定棋中每走一格代表实地距离200米，每走一步代表作战时间五分钟。<br>这样，在战棋中机动力最差的步兵单位一步最多走几格就停下来了，而这种移动格数的规定与实战一样，<br>依地型，道路条件而异。然后在规定的这一步中，依靠胜余机会力的大小，规定这只步兵队能够攻击几次，<br>依据其命中、摧毁概率来计划成果，然后再加上所处地形的防御、天候、视野、士气、战斗力等等数值，<br>以及指挥、通信、空袭、后方炮击、空投、侦察等等制约，这样一套战棋游戏就活灵活现的出来了。 <br><br><br>5、战棋的AI<br>在一个外行人眼里看来，战棋游戏不过是让自己的机动单位能走多远走多远，然后迅速的将敌人消灭的<br>普通游戏，其实是不然的，严格的来讲，战棋游戏（特别是六角格战棋游戏）较之即时战略游戏，是更<br>能体现现代战争的风貌的，在战棋游戏里，你不能一味味傻傻在往前冲，你要考虑到敌人的机动力，自<br>己的攻击能力等等，将这些多方面的因素综合的考虑起来，你才可以取得最后的胜利。 <br><br><br>6、战棋的地图风格<br><br>一般的来讲，一个战棋游戏他的地图是分是以下的规格的，分别有60＊60　80＊80　120＊120　160＊160　256＊256<br>等等，分别用于表现多种不同的战役模式，比如说如果要表现诺曼底登陆，如果用宏观的表现方法<br>本着越大越好的原则那肯定是不现实的，而且地图太大，反面会使玩家手忙脚乱，到不如用一幅<br>160＊160的图表现一下。<br><br>战棋游戏的地图风格根据地区的不同也会划分成几个不同的风格，比如说欧美，战棋游戏大多数是<br>以历史上的真实战役为蓝本，再要不然就是让某一个国家去完成统一的大任，再加上他们是六角格<br>战棋游戏，用Q版来表现肯定是不现实的，所以在欧美的战棋游戏中，你一般看见的地图风格都是<br>按照实际地图比例1：X压缩而成的，我们可以在地图上看到城市、乡村、河流、山脉等等。<br><br><br>近年来在欧美，战棋游戏题材越做越敏感，使得几乎世界各国的领土都出现过在战棋游戏中的地图上，<br>比如《装甲元帅》里有斯大林格勒战役、《西线风云》里有阿登战役、而《人民元帅》里更是因为<br>意识形态的原因弄出了一些预测未来的荒唐的战役大肆渲染中国威胁论。<br><br>据说SSI的游戏《人民元帅》曾被我国禁止（并没有见到相关的公文），这里在讨论涉及该游戏并不<br>表示赞同游戏中的观点。随着接下来几年世界局势的变幻以及游戏制作组的倾向等等原因，这种战<br>役设定也许会逐步的多起来，或许预测未来的战役才更符合并棋推演的初衷。<br><br>&nbsp;&nbsp; 我国自古以来就有用棋戏的方法研究战争，然而到了进代却由于不重视，却逐渐失传，而如今，<br>&nbsp;&nbsp; 时代发展了，条件变化了，研究战争的方法也要变化，要在和平环境中不断增加应付下一场战争<br>&nbsp;&nbsp; 的战争的经验，战棋无疑是一个好的选择，我们需要脚踏实地去迎接已经席卷世界的这一套战棋<br>&nbsp;&nbsp; 游戏，在地球的另一半世界里，我们将证明无愧于自己的祖先！<br><br>本文参考文献：<br>杨南征先生《兵与棋》<br>于翔的战棋（SLG）游戏可行性研究报告
<br><img src ="http://www.cnitblog.com/kenlistian/aggbug/43896.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/kenlistian/" target="_blank">kenlistian</a> 2008-05-19 17:38 <a href="http://www.cnitblog.com/kenlistian/archive/2008/05/19/43896.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>游戏分类</title><link>http://www.cnitblog.com/kenlistian/archive/2008/05/07/43468.html</link><dc:creator>kenlistian</dc:creator><author>kenlistian</author><pubDate>Wed, 07 May 2008 06:03:00 GMT</pubDate><guid>http://www.cnitblog.com/kenlistian/archive/2008/05/07/43468.html</guid><wfw:comment>http://www.cnitblog.com/kenlistian/comments/43468.html</wfw:comment><comments>http://www.cnitblog.com/kenlistian/archive/2008/05/07/43468.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/kenlistian/comments/commentRss/43468.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/kenlistian/services/trackbacks/43468.html</trackback:ping><description><![CDATA[<p>游戏大的类别：<br>RTG&nbsp;&nbsp;&nbsp;&nbsp; (Real-Time Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 即时游戏<br>TBG&nbsp;&nbsp;&nbsp;&nbsp; (Turn-Based Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 回合制游戏<br>OLG&nbsp;&nbsp;&nbsp;&nbsp; (Online Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在线游戏(这个缩写好像只有中国才有--b) <p>种类：<br>RPG&nbsp;&nbsp;&nbsp;&nbsp; (Role Playing Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 角色扮演游戏，例如《暗黑破坏神》<br>AVG&nbsp;&nbsp;&nbsp;&nbsp; (Adventure Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 冒险游戏，例如《国王密使》<br>ACT&nbsp;&nbsp;&nbsp;&nbsp; (Action Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 动作游戏，例如《鬼武者》<br>STG&nbsp;&nbsp;&nbsp;&nbsp; (Shooting Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 射击游戏，例如《三角洲部队》，三角洲部队有第一人称模式。<br>FPS&nbsp;&nbsp;&nbsp;&nbsp; (First Person Shooting)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 第一人称射击游戏，例如《反恐精英》<br>FTG&nbsp;&nbsp;&nbsp;&nbsp; (Fighting Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 格斗游戏，例如《KOF》 <p>RTS&nbsp;&nbsp;&nbsp;&nbsp; (Real-Time Strategy Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 即时战略游戏，例如《星际争霸》<br>RTM&nbsp;&nbsp;&nbsp;&nbsp; (Real-Time Military Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 即时战术游戏，例如《盟军敢死队》<br>TBS&nbsp;&nbsp;&nbsp;&nbsp; (Turn-Based Strategy Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 回合制策略游戏，例如《魔法门之英雄无敌》 <p>RAC&nbsp;&nbsp;&nbsp;&nbsp; (Race Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 赛车游戏，例如《NFS》<br>SLG/SIM (Simulation Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 模拟游戏，例如《模拟城市》<br></p> <p>EDU&nbsp;&nbsp;&nbsp;&nbsp; (Education Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 养成游戏，例如《明星志愿》<br>SPT&nbsp;&nbsp;&nbsp;&nbsp; (Sport Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 体育游戏，例如《FIFA》<br>PUZ&nbsp;&nbsp;&nbsp;&nbsp; (Puzzle Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 益智游戏，例如《五子棋大师》<br>TAB&nbsp;&nbsp;&nbsp;&nbsp; (Table Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 桌面游戏，例如《桌面弹球》</p> <p>扩展种类：<br>ARPG&nbsp;&nbsp;&nbsp; (Action RPG)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 动作角色扮演游戏，例如《刀剑封魔录》<br>SRPG&nbsp;&nbsp;&nbsp; (Simulation RPG)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 模拟角色扮演游戏，例如《风色幻想》<br>AAVG&nbsp;&nbsp;&nbsp; (Action Adventure Game)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 动作冒险游戏，例如《古墓丽影》<br>SFTG&nbsp;&nbsp;&nbsp; (Simulation FTG)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 模拟格斗类游戏，找不出典型例子。<br>MMORPG&nbsp; (Massively Multiplayer Online RPG)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 大型多人在线角色扮演游戏，例如《传奇》<br>MMOARPG (Massively Multiplayer Online ARPG)&nbsp;&nbsp;&nbsp;&nbsp; 大型多人在线动作角色扮演游戏，例如《刀剑Online》<br>MMOSRPG (Massively Multiplayer Online SRPG)&nbsp;&nbsp;&nbsp;&nbsp; 大型多人在线模拟角色扮演游戏，例如《傲世Online》 <p>其他类：<br>ETC&nbsp;&nbsp;&nbsp;&nbsp; (etc.)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其他类游戏，无法被归为以上种类的游戏一般都认为是其他类，</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 随着时间推移，新的游戏种类不断推出，这些“其他类”游戏最终会拥有一个正式的名字。</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>还是有些乱，不过，我认为游戏分为如下：</p> <p>1.第一人称类游戏&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 不管是动作类，角色，还是射击类，都是构建在虚拟真实模拟下。</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这类游戏一般架构在即时环境下。</p> <p>&nbsp;</p> <p>2.第三人称类：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 属于操纵类游戏了，包括即使，回合，动作；如果从技术讲就有2d，3d的实现。</p> <p>&nbsp;</p> <p>3.益智类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这个就是纯粹靠游戏强大的算法来支持了，</p><img src ="http://www.cnitblog.com/kenlistian/aggbug/43468.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/kenlistian/" target="_blank">kenlistian</a> 2008-05-07 14:03 <a href="http://www.cnitblog.com/kenlistian/archive/2008/05/07/43468.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ansi，gb2312，utf-8笔记</title><link>http://www.cnitblog.com/kenlistian/archive/2008/02/27/40206.html</link><dc:creator>kenlistian</dc:creator><author>kenlistian</author><pubDate>Wed, 27 Feb 2008 04:04:00 GMT</pubDate><guid>http://www.cnitblog.com/kenlistian/archive/2008/02/27/40206.html</guid><wfw:comment>http://www.cnitblog.com/kenlistian/comments/40206.html</wfw:comment><comments>http://www.cnitblog.com/kenlistian/archive/2008/02/27/40206.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/kenlistian/comments/commentRss/40206.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/kenlistian/services/trackbacks/40206.html</trackback:ping><description><![CDATA[&nbsp; ANSI-----&gt;<layer id="google-toolbar-hilite-5" style="background-color: Cyan; color: black;">GB2312</layer>------&gt;<layer id="google-toolbar-hilite-0" style="background-color: Yellow; color: black;">GBK</layer><br>&nbsp; Unicode----&gt;utf-8<br>&nbsp;<br>ASCII：是编码，它映射了127个字符，因此7位(bit)二进制数足够用来表示127个字符。<br>Unicode：为每个字符提供了唯一的特定数值，它世界上使用的所有字符都列出来，并给每一个字符一个唯一特定数值。<br>&nbsp;&nbsp; 通常Unicode编码指的是utf-16，如在文本中以unicode存储的话则是指UTF-16。在vc环境中就是wchar，宽字节。<br>Utf-8 则是unicode的中的一种编码方式。<br><layer id="google-toolbar-hilite-6" style="background-color: Cyan; color: black;">GB2312</layer>: 或<layer id="google-toolbar-hilite-7" style="background-color: Cyan; color: black;">GB2312</layer>-80是一个简体中文字符集的中国国家标准，全称为《信息交换用汉字编码字符集--基本集》，由中国国家标准总局发布，1981年5月1日实施。<layer id="google-toolbar-hilite-8" style="background-color: Cyan; color: black;">GB2312</layer>编码通行于大陆，几乎所有的中文系统和国际化的软件都支持<layer id="google-toolbar-hilite-9" style="background-color: Cyan; color: black;">GB2312</layer>。 是一种编码字符集。<br><layer id="google-toolbar-hilite-1" style="background-color: Yellow; color: black;">GBK</layer> 理解为则是<layer id="google-toolbar-hilite-10" style="background-color: Cyan; color: black;">GB2312</layer> 的扩展集。gbk和gb2312不存在转换<br>BIG5 台湾人用的中文字符集合。<br>&nbsp; <br><br>当unicode-&gt;<layer id="google-toolbar-hilite-11" style="background-color: Cyan; color: black;">gb2312</layer> or <layer id="google-toolbar-hilite-12" style="background-color: Cyan; color: black;">gb2312</layer>-&gt;unicode 时，存在着<layer id="google-toolbar-hilite-18" style="background-color: Fuchsia; color: black;">转换</layer>函数。<br>当utf-8-&gt;<layer id="google-toolbar-hilite-13" style="background-color: Cyan; color: black;">gb2312</layer> or <layer id="google-toolbar-hilite-14" style="background-color: Cyan; color: black;">gb2312</layer>-&gt;utf-8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 也存在<layer id="google-toolbar-hilite-19" style="background-color: Fuchsia; color: black;">转换</layer>。<br>当utf-8-&gt;unicode or unicode-&gt;utf-8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 也存在<layer id="google-toolbar-hilite-20" style="background-color: Fuchsia; color: black;">转换</layer>。<br>当然也存在<br>&nbsp; <layer id="google-toolbar-hilite-2" style="background-color: Yellow; color: black;">gbk</layer> 到&nbsp; unicode 和 unicode 到<layer id="google-toolbar-hilite-3" style="background-color: Yellow; color: black;">gbk</layer>的<layer id="google-toolbar-hilite-21" style="background-color: Fuchsia; color: black;">转换</layer><br><br>干脆列个表吧：<br>
<table style="width: 392px; height: 129px;" border="1">
    <tbody>
        <tr>
            <td><br></td>
            <td style="vertical-align: top;">unicode</td>
            <td>utf-8<br></td>
            <td style="vertical-align: top;">gb2312<br></td>
            <td style="vertical-align: top;">big5<br></td>
        </tr>
        <tr>
            <td>&nbsp;unicode<br></td>
            <td style="vertical-align: top;">-<br></td>
            <td>v<br></td>
            <td style="vertical-align: top;">v<br></td>
            <td style="vertical-align: top;">v<br></td>
        </tr>
        <tr>
            <td style="vertical-align: top;">utf-8<br></td>
            <td style="vertical-align: top;">v<br></td>
            <td style="vertical-align: top;">-<br></td>
            <td style="vertical-align: top;">v<br></td>
            <td style="vertical-align: top;">v<br></td>
        </tr>
        <tr>
            <td style="vertical-align: top;"><layer id="google-toolbar-hilite-15" style="background-color: Cyan; color: black;">gb2312</layer><br></td>
            <td style="vertical-align: top;">v<br></td>
            <td style="vertical-align: top;">v<br></td>
            <td style="vertical-align: top;">-<br></td>
            <td style="vertical-align: top;">v<br></td>
        </tr>
        <tr>
            <td style="vertical-align: top;"><layer id="google-toolbar-hilite-4" style="background-color: Yellow; color: black;">big5</layer><br></td>
            <td style="vertical-align: top;">v<br></td>
            <td style="vertical-align: top;">v<br></td>
            <td style="vertical-align: top;">v<br></td>
            <td style="vertical-align: top;">-<br></td>
        </tr>
    </tbody>
</table>
<br><br>其中<layer id="google-toolbar-hilite-22" style="background-color: Fuchsia; color: black;">转换</layer>依据各自的编码原理，当然各种语言也各自的方法，如在vc中，当<layer id="google-toolbar-hilite-23" style="background-color: Fuchsia; color: black;">转换</layer>，一般就是采用的<br>WideCharToMultiByte
or MultiByteToWideChar方式倒来倒去。<br>而在asp中则一般是utf-8到gb2312or <layer id="google-toolbar-hilite-16" style="background-color: Cyan; color: black;">gb2312</layer> 到utf-8，<br>下面摘抄一段：<br>'<layer id="google-toolbar-hilite-17" style="background-color: Cyan; color: black;">gb2312</layer> -&gt;utf-8 <layer id="google-toolbar-hilite-24" style="background-color: Fuchsia; color: black;">转换</layer><br>Function chinese2unicode(Str)<br>&nbsp; dim i<br>&nbsp; dim Str_one<br>&nbsp; dim Str_unicode<br>&nbsp; for i=1 to len(Str)<br>&nbsp;&nbsp;&nbsp; Str_one=Mid(Str,i,1)<br>&nbsp;&nbsp;&nbsp; Str_unicode=Str_unicode&amp;chr(38)<br>&nbsp;&nbsp;&nbsp; Str_unicode=Str_unicode&amp;chr(35)<br>&nbsp;&nbsp;&nbsp; Str_unicode=Str_unicode&amp;chr(120)<br>&nbsp;&nbsp;&nbsp; Str_unicode=Str_unicode&amp; Hex(ascw(Str_one))<br>&nbsp;&nbsp;&nbsp; Str_unicode=Str_unicode&amp;chr(59)<br>&nbsp; next<br>&nbsp; Response.Write Str_unicode<br>end function&nbsp;&nbsp; <br><br>至于为啥细节，则需要了解它们的编码规则，这里不用讨论了，那些<layer id="google-toolbar-hilite-25" style="background-color: Fuchsia; color: black;">转换</layer>函数，在各个语言中都有人总结出来，拿来直接用即可。<br>那些编码规范，其实说来，大致了解就可以了。<br><br><br>&nbsp;
<br><br><br><br><br><br><br><br><br><br><img src ="http://www.cnitblog.com/kenlistian/aggbug/40206.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/kenlistian/" target="_blank">kenlistian</a> 2008-02-27 12:04 <a href="http://www.cnitblog.com/kenlistian/archive/2008/02/27/40206.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>lua mark1</title><link>http://www.cnitblog.com/kenlistian/archive/2007/07/26/30651.html</link><dc:creator>kenlistian</dc:creator><author>kenlistian</author><pubDate>Thu, 26 Jul 2007 01:26:00 GMT</pubDate><guid>http://www.cnitblog.com/kenlistian/archive/2007/07/26/30651.html</guid><wfw:comment>http://www.cnitblog.com/kenlistian/comments/30651.html</wfw:comment><comments>http://www.cnitblog.com/kenlistian/archive/2007/07/26/30651.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/kenlistian/comments/commentRss/30651.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/kenlistian/services/trackbacks/30651.html</trackback:ping><description><![CDATA[<p>mark 标记<br><a  href="http://hi.baidu.com/bitbull/blog/item/bc27581eca1886f61bd5768e.html">http://hi.baidu.com/bitbull/blog/item/bc27581eca1886f61bd5768e.html</a></p>
<p style="font-size: 12px;"></p><img src ="http://www.cnitblog.com/kenlistian/aggbug/30651.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/kenlistian/" target="_blank">kenlistian</a> 2007-07-26 09:26 <a href="http://www.cnitblog.com/kenlistian/archive/2007/07/26/30651.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>lua的诡异1</title><link>http://www.cnitblog.com/kenlistian/archive/2007/05/24/27559.html</link><dc:creator>kenlistian</dc:creator><author>kenlistian</author><pubDate>Thu, 24 May 2007 07:36:00 GMT</pubDate><guid>http://www.cnitblog.com/kenlistian/archive/2007/05/24/27559.html</guid><wfw:comment>http://www.cnitblog.com/kenlistian/comments/27559.html</wfw:comment><comments>http://www.cnitblog.com/kenlistian/archive/2007/05/24/27559.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/kenlistian/comments/commentRss/27559.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/kenlistian/services/trackbacks/27559.html</trackback:ping><description><![CDATA[在lua中有几个关键点必须搞清楚，这个都是需要仔细去揣摩的。
<p><br></p>
<p>一。堆栈调用</p>
<p>lua和其他语言交互是通过堆栈来操作，那么那些明明了了的调用就变成在堆栈上push和pop上做文章了。</p>
<p>比如你要取一个lua文件中的某个数值，不是一个等号就能得到，而是调用lua_getglobal()把lua中数值变量压入堆栈，然后通过lua_tostring或者lua_tonumber来获取它。如果这还可以理解的话，那么把lua文件中表的处理，则需要一系列的压栈和处理索引后才能获取。如果参数很多，还要注意索引值的正确与否。</p>
<br>二表之堆栈调用
<p>看手册时，发现这点非常不易理解。而且手册的帮助也是看得人琢磨不透。以下说明<br></p>
<h3><a name="lua_settable"><code><font color="#ff0909">lua_settable&nbsp; 表赋值<br></font></code></a></h3>
<pre><font color="#ff0909">void lua_settable (lua_State *L, int index);</font></pre>
<p><font color="#ff0909">等价 <code>t[k] = v</code> 操作，这里 <code>t</code>
理解为table，为index<code></code><span style="font-family: monospace;">索引所对应的表</span>， <code>v</code> 为值， <code>k</code>
键名。 <br></font></p>
<p><font color="#ff0909">实际上就是对表操作，再说白些，就是在堆上处理某个表的修改。其完整的操作都是先需要</font></p>
<p><font color="#ff0909">lua_pushxxx后，对某个表做t[k]=v操作。完事后，该函数弹出-2，-1处值</font></p>
<p><font color="#ff0909"><br></font></p>
<p><font color="#ff0909">英文：</font></p>
<h3><a name="lua_settable"><code><font color="#ff0909">lua_settable</font></code></a></h3>
<pre><font color="#ff0909">void lua_settable (lua_State *L, int index);</font></pre>
<p><font color="#ff0909">Does the equivalent to <code>t[k] = v</code>, where
<code>t</code> is the value at the given valid index <code>index</code>,
<code>v</code> is the value at the top of the stack, and <code>k</code> is the
value just below the top. </font></p>
<p><font color="#ff0909">This function pops both the key and the value from the
stack. As in Lua, this function may trigger a metamethod for the "newindex"
event</font> </p>
<p>其实画个图，就是这个样</p>
<p>&nbsp;索引号&nbsp; &nbsp;&nbsp; 表 &nbsp;&nbsp;&nbsp;&nbsp;
堆栈&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 堆栈相对位置</p>
<p>&nbsp;index ----&gt; t
-------&gt;v（值） &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-1</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
k （键名） &nbsp;&nbsp; &nbsp; -2</p>
<p>该操作其实对&nbsp; 表t[k]=v <br></p>
<h3><a name="lua_gettable"><code></code></a></h3>
<h3><a name="lua_gettable"><code></code></a></h3>
<h3><br></h3>
<h3><a name="lua_gettable"><code><font color="#ff8080">lua_gettable&nbsp;&nbsp;&nbsp; 取表值<br></font></code></a></h3>
<pre><font color="#ff8080">void lua_gettable (lua_State *L, int index);</font></pre>
<p><font color="#ff8080">把<code>t[k]</code> 值压入堆栈，通过lua_toxxxx取出该值。</font></p>
<p><font color="#ff8080"><code></code>
<code>index</code> 指向某个表，而 <code>k</code> 则为某个表的键名。调用该函数时，需要先压入一个k，表（索引）键名。</font></p>
<p><font color="#ff8080">调用该函数，其实就是在堆中把t[k]的值获取处理，完事后弹出k，而返回的表值在堆的顶部（-1处）。</font></p>
<br>
<p>拿个例子来讲最生动：<br>比如调用一个函数，其中函数是在lua中定义的表中的函数，即：</p>
<p>mytable = {<br>&nbsp;&nbsp; Function1 = function (var ) return var.."world，my
test" end<br>}<br>。。。<br>lua_pushstring(L,
"mytable");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
--压表名，将在全局栈中找该表<br>lua_gettable(L,
LUA_GLOBALSINDEX);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --<font color="#004080">以表名查表在全局表中的位置，</font><font color="#004080"></font>结果在堆顶<br>lua_pushstring(L,
"Function1");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
--压函数名，&#8220;Function1&#8221;在堆栈-1处，<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font color="#004080">mytable的表索引在-2位置（不是字符串）</font><br>lua_gettable(L,
-2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; <span style="color: #606aff;">--在mytable表中查找function1的索引值（指针），<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 该操作完后，栈顶为function1函数指针。</span><br><br>lua_pushstring("hello");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
--压参<br>lua_pcall(L, 1, 1, 0);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --调用函数，返回一个参数。<br>lua_String&nbsp;msg = lua_tostring(L,
-1);<br>lua_pop(L, 1);</p>
<p>四 <a name="2.10">垃圾收集</a></p>
<p>&nbsp; 这个概念是这样的：<br>&nbsp;&nbsp;
lua不需要用户干预内存的操作，只是通过垃圾收集器来自动管理内存。所有对象都被自动管理，有： table, userdata、 函数、线程、和字符串。
<br>&nbsp; 其管理机制是：通过递增的标志来决定是否收集，用2个标记数字来控制垃圾收集周期： <br><em>garbage-collector
pause</em> 和 <em>garbage-collector step multiplier</em> 。 </p>
<p>collector pause&nbsp; 按收集周期决定收集内存，当其数值越大，则收集周期也越长。<br>step
multiplier&nbsp;&nbsp; 按相对内存分配的速度来收集。数值越大收集器则收集更快。</p><img src ="http://www.cnitblog.com/kenlistian/aggbug/27559.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/kenlistian/" target="_blank">kenlistian</a> 2007-05-24 15:36 <a href="http://www.cnitblog.com/kenlistian/archive/2007/05/24/27559.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>