﻿<?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++博客-Error-随笔分类-lua</title><link>http://www.cppblog.com/Error/category/21140.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 03 Sep 2015 04:41:20 GMT</lastBuildDate><pubDate>Thu, 03 Sep 2015 04:41:20 GMT</pubDate><ttl>60</ttl><item><title>pack简单用法</title><link>http://www.cppblog.com/Error/archive/2015/09/01/211737.html</link><dc:creator>Enic</dc:creator><author>Enic</author><pubDate>Tue, 01 Sep 2015 10:30:00 GMT</pubDate><guid>http://www.cppblog.com/Error/archive/2015/09/01/211737.html</guid><wfw:comment>http://www.cppblog.com/Error/comments/211737.html</wfw:comment><comments>http://www.cppblog.com/Error/archive/2015/09/01/211737.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Error/comments/commentRss/211737.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Error/services/trackbacks/211737.html</trackback:ping><description><![CDATA[<div>bpack=string.pack</div><div>bunpack=string.unpack</div><div></div><div>-- 输出二进制</div><div>function hex(s)</div><div>&nbsp;s=string.gsub(s,"(.)",function (x) return string.format("%02X",string.byte(x)) end)</div><div>&nbsp;return s</div><div>end</div><div></div><div>--解包传入的是hex和FMT(&gt;&lt;大小端)，输出是FMT指定的类型：i int, n lua_num</div><div>--i=12345 f="i"</div><div>--a=bpack(f,i,i,i)</div><div>--print(hex(a))</div><div>--print(bunpack(a,f))</div><div></div><div>--打包输入fmt，实际类型，输出hex</div><div>local n = 0x12345678</div><div>--tb = {}</div><div>--dump(tb)</div><div>--tb = n</div><div>--dump(tb)</div><div>a = bpack('&gt;n', n)</div><div>dump(hex(a))</div><img src ="http://www.cppblog.com/Error/aggbug/211737.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Error/" target="_blank">Enic</a> 2015-09-01 18:30 <a href="http://www.cppblog.com/Error/archive/2015/09/01/211737.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>LUA枚举</title><link>http://www.cppblog.com/Error/archive/2015/09/01/211735.html</link><dc:creator>Enic</dc:creator><author>Enic</author><pubDate>Tue, 01 Sep 2015 09:29:00 GMT</pubDate><guid>http://www.cppblog.com/Error/archive/2015/09/01/211735.html</guid><wfw:comment>http://www.cppblog.com/Error/comments/211735.html</wfw:comment><comments>http://www.cppblog.com/Error/archive/2015/09/01/211735.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Error/comments/commentRss/211735.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Error/services/trackbacks/211735.html</trackback:ping><description><![CDATA[<div>--如何定义枚举</div><div>--下面的函数实现：</div><div>--转换 EnumTable = {1:Enum1, 2:Enum2}</div><div>--到 &nbsp; EnumTable = {Enum1:1, Enum2:2}</div><div>function CreateEnumTable(tb, indexStart)</div><div>&nbsp; &nbsp; --assert(IsTable(tb))</div><div>&nbsp; &nbsp; local enumTB = {}</div><div>&nbsp; &nbsp; local enumIndex = indexStart or 0</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; --转换字符table到枚举table</div><div>&nbsp; &nbsp; for index, value ipairs(tb) do</div><div>&nbsp; &nbsp; &nbsp; &nbsp; enumTB[v] = enumIndex + index</div><div>&nbsp; &nbsp; end</div><div></div><div>&nbsp; &nbsp; return enumTB</div><div>end</div><div></div><div>--只是返回值而已和C不一样</div><div>assert(0)</div><div>--用这个和字符串比较实现判断变量类型</div><div>print(type(CreateEnumTable))</div><div>--xpcall可以保护执行一个函数，通过返回值确定异常情况</div><img src ="http://www.cppblog.com/Error/aggbug/211735.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Error/" target="_blank">Enic</a> 2015-09-01 17:29 <a href="http://www.cppblog.com/Error/archive/2015/09/01/211735.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>wxLua01： 第一个wxLua程序，除了很多错误不能直接编译出来，总的感觉比C++来的舒服多了</title><link>http://www.cppblog.com/Error/archive/2015/08/14/211560.html</link><dc:creator>Enic</dc:creator><author>Enic</author><pubDate>Fri, 14 Aug 2015 07:43:00 GMT</pubDate><guid>http://www.cppblog.com/Error/archive/2015/08/14/211560.html</guid><wfw:comment>http://www.cppblog.com/Error/comments/211560.html</wfw:comment><comments>http://www.cppblog.com/Error/archive/2015/08/14/211560.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Error/comments/commentRss/211560.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Error/services/trackbacks/211560.html</trackback:ping><description><![CDATA[<div>require("wx")</div><div></div><div>--文档需要结合wxWidget和wxLua来看，wxLua中明确的指定的导出的接口名字有些和wxWidget中不一样</div><div></div><div>--wx.wxFrame只有一个子空间的时候会自动拉伸，所以用DLG把</div><div>dlg = wx.wxDialog(wx.NULL, wx.wxID_ANY, "wxLua例子",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wx.wxDefaultPosition, wx.wxSize(450,450),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wx.wxDEFAULT_FRAME_STYLE)</div><div></div><div>--创建新的ID</div><div>local ID_BTN_0 = wx.wxNewId();</div><div>local ID_BTN_1 = wx.wxNewId();</div><div></div><div>--使用ID创建button</div><div>btn = wx.wxButton(dlg, ID_BTN_0, "Button", wx.wxPoint(90,0), wx.wxSize(30,60))</div><div>btn:SetSize(wx.wxSize(30,60))</div><div>--btn:SetPosition(wx.wxPoint(0,0))</div><div></div><div>--设置按钮事件</div><div>dlg:Connect(ID_BTN_1, wx.wxEVT_COMMAND_BUTTON_CLICKED,</div><div>&nbsp; &nbsp; function(event)&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; wx.wxMessageBox("", "1")</div><div>&nbsp; &nbsp; end</div><div>)</div><div></div><div></div><div>--C++版sdk是SetPositon，这里必须用move，很奇怪</div><div>btn1 = wx.wxButton(dlg, ID_BTN_1, "Button1", wx.wxPoint(0,0), wx.wxSize(30,60))</div><div>btn1:Move(wx.wxPoint(99,99))</div><div></div><div>dlg:Move(wx.wxPoint(99,99))</div><div>dlg:Show(true)</div><div></div><div>wx.wxGetApp():MainLoop()</div><div></div><div></div><img src ="http://www.cppblog.com/Error/aggbug/211560.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Error/" target="_blank">Enic</a> 2015-08-14 15:43 <a href="http://www.cppblog.com/Error/archive/2015/08/14/211560.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>