﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-剑孤寒的小站-随笔分类-Lua</title><link>http://www.cppblog.com/jianguhan/category/15962.html</link><description>人生的价值不是用时间，而是用深度去衡量的！</description><language>zh-cn</language><lastBuildDate>Sun, 10 Aug 2014 21:07:17 GMT</lastBuildDate><pubDate>Sun, 10 Aug 2014 21:07:17 GMT</pubDate><ttl>60</ttl><item><title>xls2lua  写了个xls转换成lua表的工具，只有一个exe文件，绿色免费无公害^_^</title><link>http://www.cppblog.com/jianguhan/archive/2014/08/08/207946.html</link><dc:creator>剑孤寒</dc:creator><author>剑孤寒</author><pubDate>Fri, 08 Aug 2014 10:43:00 GMT</pubDate><guid>http://www.cppblog.com/jianguhan/archive/2014/08/08/207946.html</guid><wfw:comment>http://www.cppblog.com/jianguhan/comments/207946.html</wfw:comment><comments>http://www.cppblog.com/jianguhan/archive/2014/08/08/207946.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jianguhan/comments/commentRss/207946.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jianguhan/services/trackbacks/207946.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 写了个xls转换成lua表的工具，只有一个exe文件，绿色免费无公害^_^<br>用法：<br>xls2lua.exe xlsfile luafile [-n] [-i]<br>xlsfile:要转换的xls文件名<br>luafile:转换后的lua文件名<br>-n:可选参数，当xls文件有修改时才转换<br>-i:可选参数，xls表单第一列作为lua表的索引&nbsp;&nbsp;<a href='http://www.cppblog.com/jianguhan/archive/2014/08/08/207946.html'>阅读全文</a><img src ="http://www.cppblog.com/jianguhan/aggbug/207946.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jianguhan/" target="_blank">剑孤寒</a> 2014-08-08 18:43 <a href="http://www.cppblog.com/jianguhan/archive/2014/08/08/207946.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一张图彻底掌握Lua栈概念</title><link>http://www.cppblog.com/jianguhan/archive/2013/04/09/199274.html</link><dc:creator>剑孤寒</dc:creator><author>剑孤寒</author><pubDate>Tue, 09 Apr 2013 08:41:00 GMT</pubDate><guid>http://www.cppblog.com/jianguhan/archive/2013/04/09/199274.html</guid><wfw:comment>http://www.cppblog.com/jianguhan/comments/199274.html</wfw:comment><comments>http://www.cppblog.com/jianguhan/archive/2013/04/09/199274.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jianguhan/comments/commentRss/199274.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jianguhan/services/trackbacks/199274.html</trackback:ping><description><![CDATA[很鄙视网上一些教程，把本来很简单的Lua栈概念搞得各种复杂，这是我之前给公司同事做Lua培训时画的图，熟记此图即可彻底掌握Lua栈概念<br /><br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/jianguhan/0724454ECCF041BAAACFB493834DB887.jpg" /><img src ="http://www.cppblog.com/jianguhan/aggbug/199274.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jianguhan/" target="_blank">剑孤寒</a> 2013-04-09 16:41 <a href="http://www.cppblog.com/jianguhan/archive/2013/04/09/199274.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>终于找到了！最好用最轻量级的lua/c++ wrapper</title><link>http://www.cppblog.com/jianguhan/archive/2012/10/09/193051.html</link><dc:creator>剑孤寒</dc:creator><author>剑孤寒</author><pubDate>Tue, 09 Oct 2012 02:33:00 GMT</pubDate><guid>http://www.cppblog.com/jianguhan/archive/2012/10/09/193051.html</guid><wfw:comment>http://www.cppblog.com/jianguhan/comments/193051.html</wfw:comment><comments>http://www.cppblog.com/jianguhan/archive/2012/10/09/193051.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jianguhan/comments/commentRss/193051.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jianguhan/services/trackbacks/193051.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 终于找到了！最好用最轻量级的lua/c++ wrapper&nbsp;&nbsp;<a href='http://www.cppblog.com/jianguhan/archive/2012/10/09/193051.html'>阅读全文</a><img src ="http://www.cppblog.com/jianguhan/aggbug/193051.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jianguhan/" target="_blank">剑孤寒</a> 2012-10-09 10:33 <a href="http://www.cppblog.com/jianguhan/archive/2012/10/09/193051.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在Lua中使用枚举型变量 </title><link>http://www.cppblog.com/jianguhan/archive/2008/10/26/65066.html</link><dc:creator>剑孤寒</dc:creator><author>剑孤寒</author><pubDate>Sun, 26 Oct 2008 03:07:00 GMT</pubDate><guid>http://www.cppblog.com/jianguhan/archive/2008/10/26/65066.html</guid><wfw:comment>http://www.cppblog.com/jianguhan/comments/65066.html</wfw:comment><comments>http://www.cppblog.com/jianguhan/archive/2008/10/26/65066.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/jianguhan/comments/commentRss/65066.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jianguhan/services/trackbacks/65066.html</trackback:ping><description><![CDATA[《在Lua中使用枚举型变量》 <br>转载请注明出处：<a href="http://groups.google.com/group/jianguhan" rel=nofollow target=_blank>http://groups.google.com/group/jianguhan</a> <br><br><br>
<p>用lua来写游戏脚本的确是一件很方便的事情，但是有时候需要用到枚举类型时就有点麻烦了，因为lua里时没有枚举型变量这个东西的，所以要使用枚举还 得自己转换一下，我写了一个函数用来做这种转换： <br>
<p>function CreatEnumTable(tbl, index) <br>&nbsp; &nbsp; assert(IsTable(tbl)) <br>&nbsp; &nbsp; local enumtbl = {} <br>&nbsp; &nbsp; local enumindex = index or 0 <br>&nbsp; &nbsp; for i, v in ipairs(tbl) do <br>&nbsp; &nbsp; &nbsp; &nbsp; enumtbl[v] = enumindex + i <br>&nbsp; &nbsp; end <br>&nbsp; &nbsp; return enumtbl <br>end <br>
<p>在需要用到枚举变量的地方只要这样用就行了： <br>EnumTable = <br>{ <br>&nbsp; &nbsp; "ET1", <br>&nbsp; &nbsp; "ET2", <br>}<br><br>EnumTable = CreatEnumTable(EnumTable ) <br>print(EnumTable.ET1) <br>print(EnumTable.ET2) <br>
<p>输出为： <br>1 <br>2 <br>
<p>当然，也可以指定下标从多少开始， <br>比如从10开始，只要把上面创建枚举表的语句换成下面这样就可以了： <br>EnumTable = CreatEnumTable(EnumTable, 10) </p>
<img src ="http://www.cppblog.com/jianguhan/aggbug/65066.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jianguhan/" target="_blank">剑孤寒</a> 2008-10-26 11:07 <a href="http://www.cppblog.com/jianguhan/archive/2008/10/26/65066.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在Lua中使用List </title><link>http://www.cppblog.com/jianguhan/archive/2008/10/26/65065.html</link><dc:creator>剑孤寒</dc:creator><author>剑孤寒</author><pubDate>Sun, 26 Oct 2008 03:06:00 GMT</pubDate><guid>http://www.cppblog.com/jianguhan/archive/2008/10/26/65065.html</guid><wfw:comment>http://www.cppblog.com/jianguhan/comments/65065.html</wfw:comment><comments>http://www.cppblog.com/jianguhan/archive/2008/10/26/65065.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jianguhan/comments/commentRss/65065.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jianguhan/services/trackbacks/65065.html</trackback:ping><description><![CDATA[《在Lua中使用List 》<br>转载请注明出处：<a href="http://groups.google.com/group/jianguhan" rel=nofollow target=_blank><u><font color=#800080>http://groups.google.com/group/jianguhan</font></u></a> <br><br><br>
<p>在《Programming in Lua》一书中提到了一个双端队列的实现方法，我把它拿来改进了一下用在了我正在制作的一个RPG游戏里，用起觉得 来还不错，加了一个GetSize()来取得List的大小，这个在游戏制作中用处还是很大的^_^ <br>
<p>源代码如下： <br>CList = class() <br>
<p>function CList:ctor() <br>&nbsp; &nbsp; &nbsp; &nbsp; self.m_list = { first = 0, last = -1 } <br>end <br>
<p>function CList:PushFront(value) <br>&nbsp; &nbsp; &nbsp; &nbsp; local first = self.m_list.first - 1 <br>&nbsp; &nbsp; &nbsp; &nbsp; self.m_list.first = first <br>&nbsp; &nbsp; &nbsp; &nbsp; self.m_list[first] = value <br>end <br>
<p>function CList:PushBack(value) <br>&nbsp; &nbsp; &nbsp; &nbsp; local last = self.m_list.last + 1 <br>&nbsp; &nbsp; &nbsp; &nbsp; self.m_list.last = last <br>&nbsp; &nbsp; &nbsp; &nbsp; self.m_list[last] = value <br>end <br>
<p>function CList:PopFront() <br>&nbsp; &nbsp; &nbsp; &nbsp; local first = self.m_list.first <br>&nbsp; &nbsp; &nbsp; &nbsp; if first &gt; self.m_list.last then return nil end <br>&nbsp; &nbsp; &nbsp; &nbsp; local value = self.m_list[first] <br>&nbsp; &nbsp; &nbsp; &nbsp; self.m_list[first] = nil <br>&nbsp; &nbsp; &nbsp; &nbsp; self.m_list.first = first + 1 <br>&nbsp; &nbsp; &nbsp; &nbsp; return value <br>end <br>
<p>function CList:PopBack() <br>&nbsp; &nbsp; &nbsp; &nbsp; local last = self.m_list.last <br>&nbsp; &nbsp; &nbsp; &nbsp; if self.m_list.first &gt; last then return nil end <br>&nbsp; &nbsp; &nbsp; &nbsp; local value = self.m_list[last] <br>&nbsp; &nbsp; &nbsp; &nbsp; self.m_list[last] = nil <br>&nbsp; &nbsp; &nbsp; &nbsp; self.m_list.last = last - 1 <br>&nbsp; &nbsp; &nbsp; &nbsp; return value <br>end <br>
<p>function CList:GetSize() <br>&nbsp; &nbsp; &nbsp; &nbsp; if self.m_list.first &gt; self.m_list.last then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0 <br>&nbsp; &nbsp; &nbsp; &nbsp; else <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return math.abs(self.m_list.last - self.m_list.first) + 1 <br>&nbsp; &nbsp; &nbsp; &nbsp; end <br>end <br>
<p>在最前面的那句CList = class() 这里使用了云风写的一个class函数创建一个类， <br>这个函数可以在云风的博客上找到，为了方便起见我就在这里先抄一下了： <br>
<p>local _class={} <br>
<p>function class(super) <br>&nbsp; &nbsp; &nbsp; &nbsp; local class_type={} <br>&nbsp; &nbsp; &nbsp; &nbsp; class_type.ctor=false <br>&nbsp; &nbsp; &nbsp; &nbsp; class_type.super=super <br>&nbsp; &nbsp; &nbsp; &nbsp; class_type.new=function(...) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local obj={} <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; do <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local create <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; create = function(c,...) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if c.super then <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; create(c.super,...) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if c.ctor then <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; c.ctor(obj,...) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end <br>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; create(class_type,...) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setmetatable(obj,{ __index=_class[class_type] }) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return obj <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end <br>&nbsp; &nbsp; &nbsp; &nbsp; local vtbl={} <br>&nbsp; &nbsp; &nbsp; &nbsp; _class[class_type]=vtbl <br>
<p>&nbsp; &nbsp; &nbsp; &nbsp; setmetatable(class_type,{__newindex= <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function(t,k,v) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vtbl[k]=v <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end <br>&nbsp; &nbsp; &nbsp; &nbsp; }) <br>
<p>&nbsp; &nbsp; &nbsp; &nbsp; if super then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setmetatable(vtbl,{__index= <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function(t,k) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local ret=_class[super][k] <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vtbl[k]=ret <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return ret <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }) <br>&nbsp; &nbsp; &nbsp; &nbsp; end <br>
<p>&nbsp; &nbsp; &nbsp; &nbsp; return class_type <br>end </p>
<img src ="http://www.cppblog.com/jianguhan/aggbug/65065.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jianguhan/" target="_blank">剑孤寒</a> 2008-10-26 11:06 <a href="http://www.cppblog.com/jianguhan/archive/2008/10/26/65065.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>