﻿<?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++博客-清源游民的网络笔记本-随笔分类-MFC</title><link>http://www.cppblog.com/yuanyajie/category/10377.html</link><description>记录所思所想，收藏所见所闻�?
</description><language>zh-cn</language><lastBuildDate>Sat, 09 May 2009 09:41:30 GMT</lastBuildDate><pubDate>Sat, 09 May 2009 09:41:30 GMT</pubDate><ttl>60</ttl><item><title>试用新版本luabind</title><link>http://www.cppblog.com/yuanyajie/archive/2009/05/07/82117.html</link><dc:creator>清源游民</dc:creator><author>清源游民</author><pubDate>Wed, 06 May 2009 16:46:00 GMT</pubDate><guid>http://www.cppblog.com/yuanyajie/archive/2009/05/07/82117.html</guid><wfw:comment>http://www.cppblog.com/yuanyajie/comments/82117.html</wfw:comment><comments>http://www.cppblog.com/yuanyajie/archive/2009/05/07/82117.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yuanyajie/comments/commentRss/82117.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yuanyajie/services/trackbacks/82117.html</trackback:ping><description><![CDATA[环境xp sp3 , vs2008 sp1, luabind 0.8.1,lua 5.1.4 , boost 1_36_0<br>先把lua, luabind 编成静态库，（下图只是debug,release类似)：<br><br><img src="http://www.cppblog.com/images/cppblog_com/yuanyajie/lua_bind_lib.png" border=0><br>做完之后整理，lua, luabind 以sdk 形式组织好，我是这样组织:<br>\luabind_build\sdk\luabind\include<br>\luabind_build\sdk\luabind\msvc-9.0-sp1\lib<br>\luabind_build\sdk\lua\include<br>\luabind_build\sdk\lua\msvc-9.0-sp1\lib<br>这样，把sdk中的东东保存一份，方便以后使用。写一个MFC小程序测试<br><img src="http://www.cppblog.com/images/cppblog_com/yuanyajie/mfc_lua.png" border=0><br><br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">&nbsp;1</span>&nbsp;<span style="COLOR: #008000">//</span><span style="COLOR: #008000">关键代码<br></span><span style="COLOR: #008080">&nbsp;2</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">mfc&nbsp;class&nbsp;function</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;3</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;CMFC_LuaDlg::SetEditText(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;text)<br></span><span style="COLOR: #008080">&nbsp;4</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;5</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Edit_1.SetWindowText(text);<br></span><span style="COLOR: #008080">&nbsp;6</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;UpdateData(FALSE);<br></span><span style="COLOR: #008080">&nbsp;7</span>&nbsp;<span style="COLOR: #000000">}<br></span><span style="COLOR: #008080">&nbsp;8</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">register</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;9</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #000000">luabind::module(L)<br></span><span style="COLOR: #008080">10</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;[<br></span><span style="COLOR: #008080">11</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;luabind::class_</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">CMFC_LuaDlg</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">mfc_dlg</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">12</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.def</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">set_text</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">CMFC_LuaDlg::SetEditText)<br></span><span style="COLOR: #008080">13</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;];<br></span><span style="COLOR: #008080">14</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">load&nbsp;lua&nbsp;file</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">15</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">luaL_dofile(L,filepath))<br></span><span style="COLOR: #008080">16</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">17</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ret</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">18</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">19</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">run&nbsp;lua&nbsp;function</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">20</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #000000">&nbsp;luabind::call_function</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">(L,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">update_text</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,dlg);<br></span><span style="COLOR: #008080">21</span>&nbsp;<span style="COLOR: #000000"></span></div>
脚本内容:<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">1</span>&nbsp;<span style="COLOR: #000000">function&nbsp;update_text(dlg)<br></span><span style="COLOR: #008080">2</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;dlg:set_text(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">你好，欢迎来到lua&nbsp;脚本世界</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">3</span>&nbsp;<span style="COLOR: #000000">end</span></div>
运行结果：<br><img src="http://www.cppblog.com/images/cppblog_com/yuanyajie/mfc_lua_ret.png" border=0><br><br>
<img src ="http://www.cppblog.com/yuanyajie/aggbug/82117.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yuanyajie/" target="_blank">清源游民</a> 2009-05-07 00:46 <a href="http://www.cppblog.com/yuanyajie/archive/2009/05/07/82117.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>