﻿<?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++博客-战魂小筑-随笔分类-C++/ 编程语言</title><link>http://www.cppblog.com/sunicdavy/category/12572.html</link><description>讨论群:309800774 知乎关注:http://zhihu.com/people/sunicdavy 开源项目:https://github.com/davyxu</description><language>zh-cn</language><lastBuildDate>Mon, 27 Dec 2021 16:42:06 GMT</lastBuildDate><pubDate>Mon, 27 Dec 2021 16:42:06 GMT</pubDate><ttl>60</ttl><item><title>参数Component通过Entity传递到System处理</title><link>http://www.cppblog.com/sunicdavy/archive/2021/12/27/217894.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Mon, 27 Dec 2021 11:04:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2021/12/27/217894.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/217894.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2021/12/27/217894.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/217894.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/217894.html</trackback:ping><description><![CDATA[ Entitas的ECS系统 1. 本来在一个对象中添加一个类字段的过程，ECS需要添加一个类代表Component，并且代码生成。 这个字段一般用于描述对象的资源，处理显示的GameObject， 表示对象的类型等。 2. 本来一个对象的业务逻辑处理过程直接用方法解决的， ECS需要新加一个System，而操作对象需要使用Filter或Group查询获得。 3. 一系列的操作， 需要拆分为多个System和Component拆分处理。如果System顺序不对， 会造成一些诡异的bug。 4. Component不仅仅是Model承载体， 也可以是参数的数据结构。参数Component通过Entity传递到System处理。 例如： 通过ECS创建一个方块的过程，使用CreateTileComponent，包含创建Tile的位置， 创建Entity并添加CreateTileComponent， 在CreateTileSystem中处理就创建了Tile，处理完成时， 需要将传入的Entity.Destroy掉。 6. Entity上修改Component的过程， 会触发事件。修改的过程需要使用RelaceXXX，XXX表示组件名。组件可以频繁修改， 不用担心添加和删除组件过程的性能， Entitas底层处理性能只相当于指针赋值的性能。 ECS像什么？ 1. ECS中的System类似触发器系统（Event-Condition-Action），其中，Event对应Entitas的GetTrigger+Collector，表示触发事件。Condition对应Filter表示在事件来源对象中找到需要的对象。 Action对应Execute，表示实际的操作。 2. ECS中的Component类似不用lua扩展的Redis或者不用存储过程的MySQL， 纯粹纯数据， 而不能对数据有任何封装操作。没有lua和存储过程支持的db写起来还是比较费劲的，但ECS就是那么的纯。 3. ECS中的Entity很尴尬，因为Component是按类别连续存储的以保证性能。 逻辑又需要Entity组合成逻辑需要的复合对象。 两边都要照顾，所以这种设计就让代码量巨增，可读性下降。 ECS企图用一套框架灭掉设计模式 1. 单件（Singleton）在Entitas用Unique标签标记Component， 在Context中就是唯一的， 其实也就是Singleton。 2. ECS干掉了传统的工厂模式，底层统一对对象（Entity）和属性（Component）统一管理。需要按Component中的值找回Entity时， 可以使用EntityIndex。

http://zhidao.baixing.com/question/11522860.html</p>
http://zhidao.baixing.com/question/11522863.html</p>
http://zhidao.baixing.com/question/11522867.html</p>
http://zhidao.baixing.com/question/11522873.html</p>
http://zhidao.baixing.com/question/11522877.html</p>
http://zhidao.baixing.com/question/11522881.html</p>
http://zhidao.baixing.com/question/11522889.html</p>
http://zhidao.baixing.com/question/11522891.html</p>
http://zhidao.baixing.com/question/11522896.html</p>
http://zhidao.baixing.com/question/11522897.html</p>
http://zhidao.baixing.com/question/11522899.html</p>
http://zhidao.baixing.com/question/11522901.html</p>
http://zhidao.baixing.com/question/11522904.html</p>
http://zhidao.baixing.com/question/11522910.html</p>
http://zhidao.baixing.com/question/11522911.html</p>
http://zhidao.baixing.com/question/11522912.html</p>
http://zhidao.baixing.com/question/11522913.html</p>
http://zhidao.baixing.com/question/11522916.html</p>
http://zhidao.baixing.com/question/11522917.html</p>
http://zhidao.baixing.com/question/11522923.html</p>
http://zhidao.baixing.com/question/11522925.html</p>
http://zhidao.baixing.com/question/11522931.html</p>
http://zhidao.baixing.com/question/11522935.html</p>
http://zhidao.baixing.com/question/11522936.html</p>
http://zhidao.baixing.com/question/11522942.html</p>
http://zhidao.baixing.com/question/11522945.html</p>
http://zhidao.baixing.com/question/11522949.html</p>
http://zhidao.baixing.com/question/11522952.html</p>
http://zhidao.baixing.com/question/11522957.html</p>
http://zhidao.baixing.com/question/11522962.html</p>
http://zhidao.baixing.com/question/11522966.html</p>
http://zhidao.baixing.com/question/11522968.html</p>
http://zhidao.baixing.com/question/11522969.html</p>
http://zhidao.baixing.com/question/11522971.html</p>
http://zhidao.baixing.com/question/11522972.html</p>
http://zhidao.baixing.com/question/11522976.html</p>
http://zhidao.baixing.com/question/11522977.html</p>
http://zhidao.baixing.com/question/11522979.html</p>
http://zhidao.baixing.com/question/11522981.html</p>
http://zhidao.baixing.com/question/11522982.html</p>
http://zhidao.baixing.com/question/11522986.html</p>
http://zhidao.baixing.com/question/11522990.html</p>
http://zhidao.baixing.com/question/11522991.html</p>
http://zhidao.baixing.com/question/11522993.html</p>
http://zhidao.baixing.com/question/11522994.html</p>
http://zhidao.baixing.com/question/11522999.html</p>
http://zhidao.baixing.com/question/11523001.html</p>
http://zhidao.baixing.com/question/11523002.html</p>
http://zhidao.baixing.com/question/11523008.html</p>
http://zhidao.baixing.com/question/11523011.html</p>
http://zhidao.baixing.com/question/11523014.html</p>
http://zhidao.baixing.com/question/11523017.html</p>
http://zhidao.baixing.com/question/11523020.html</p>
http://zhidao.baixing.com/question/11523023.html</p>
http://zhidao.baixing.com/question/11523025.html</p>
http://zhidao.baixing.com/question/11523028.html</p>
http://zhidao.baixing.com/question/11523029.html</p>
http://zhidao.baixing.com/question/11523035.html</p>
http://zhidao.baixing.com/question/11523038.html</p>
http://zhidao.baixing.com/question/11523042.html</p>
http://zhidao.baixing.com/question/11523044.html</p>
http://zhidao.baixing.com/question/11523045.html</p>
http://zhidao.baixing.com/question/11523047.html</p>
http://zhidao.baixing.com/question/11523049.html</p>
http://zhidao.baixing.com/question/11523061.html</p>
http://zhidao.baixing.com/question/11523063.html</p>
http://zhidao.baixing.com/question/11523065.html</p>
http://zhidao.baixing.com/question/11523066.html</p>
http://zhidao.baixing.com/question/11523068.html</p>
http://zhidao.baixing.com/question/11523076.html</p>
http://zhidao.baixing.com/question/11523077.html</p>
http://zhidao.baixing.com/question/11523082.html</p>
http://zhidao.baixing.com/question/11523085.html</p>
http://zhidao.baixing.com/question/11523086.html</p>
http://zhidao.baixing.com/question/11523088.html</p>
http://zhidao.baixing.com/question/11523093.html</p>
http://zhidao.baixing.com/question/11523097.html</p>
http://zhidao.baixing.com/question/11523098.html</p>
http://zhidao.baixing.com/question/11523100.html</p>
http://zhidao.baixing.com/question/11523102.html</p>
http://zhidao.baixing.com/question/11523106.html</p>
http://zhidao.baixing.com/question/11523109.html</p>
http://zhidao.baixing.com/question/11523111.html</p>
http://zhidao.baixing.com/question/11523113.html</p>
http://zhidao.baixing.com/question/11523115.html</p>
http://zhidao.baixing.com/question/11523116.html</p>
http://zhidao.baixing.com/question/11523119.html</p>
http://zhidao.baixing.com/question/11523121.html</p>
http://zhidao.baixing.com/question/11523123.html</p>
http://zhidao.baixing.com/question/11523125.html</p>
http://zhidao.baixing.com/question/11523127.html</p>
http://zhidao.baixing.com/question/11523132.html</p>
http://zhidao.baixing.com/question/11523134.html</p>
http://zhidao.baixing.com/question/11523136.html</p>
http://zhidao.baixing.com/question/11523137.html</p>
http://zhidao.baixing.com/question/11523139.html</p>
http://zhidao.baixing.com/question/11523144.html</p>
http://zhidao.baixing.com/question/11523147.html</p>
http://zhidao.baixing.com/question/11523150.html</p>
http://zhidao.baixing.com/question/11523151.html</p>
http://zhidao.baixing.com/question/11523153.html</p>
http://zhidao.baixing.com/question/11523155.html</p>
http://zhidao.baixing.com/question/11523156.html</p>
http://zhidao.baixing.com/question/11523159.html</p>
http://zhidao.baixing.com/question/11523161.html</p>
http://zhidao.baixing.com/question/11523164.html</p>
http://zhidao.baixing.com/question/11523165.html</p>
http://zhidao.baixing.com/question/11523168.html</p>
http://zhidao.baixing.com/question/11523170.html</p>
http://zhidao.baixing.com/question/11523171.html</p>
http://zhidao.baixing.com/question/11523172.html</p>
http://zhidao.baixing.com/question/11523173.html</p>
http://zhidao.baixing.com/question/11523182.html</p>
http://zhidao.baixing.com/question/11523184.html</p>
http://zhidao.baixing.com/question/11523186.html</p>
http://zhidao.baixing.com/question/11523188.html</p>
http://zhidao.baixing.com/question/11523190.html</p>
http://zhidao.baixing.com/question/11523196.html</p>
http://zhidao.baixing.com/question/11523201.html</p>
http://zhidao.baixing.com/question/11523203.html</p>
http://zhidao.baixing.com/question/11523204.html</p>
http://zhidao.baixing.com/question/11523206.html</p>
http://zhidao.baixing.com/question/11523207.html</p>
http://zhidao.baixing.com/question/11523213.html</p>
http://zhidao.baixing.com/question/11523217.html</p>
http://zhidao.baixing.com/question/11523220.html</p>
http://zhidao.baixing.com/question/11523223.html</p>
http://zhidao.baixing.com/question/11523225.html</p>
http://zhidao.baixing.com/question/11523228.html</p>
http://zhidao.baixing.com/question/11523230.html</p>
http://zhidao.baixing.com/question/11523232.html</p>
http://zhidao.baixing.com/question/11523234.html</p>
http://zhidao.baixing.com/question/11523235.html</p>
http://zhidao.baixing.com/question/11523237.html</p>
http://zhidao.baixing.com/question/11523240.html</p>
http://zhidao.baixing.com/question/11523242.html</p>
http://zhidao.baixing.com/question/11523245.html</p>
http://zhidao.baixing.com/question/11523248.html</p>
http://zhidao.baixing.com/question/11523251.html</p>
http://zhidao.baixing.com/question/11523254.html</p>
http://zhidao.baixing.com/question/11523258.html</p>
http://zhidao.baixing.com/question/11523262.html</p>
http://zhidao.baixing.com/question/11523267.html</p>
http://zhidao.baixing.com/question/11523268.html</p>
http://zhidao.baixing.com/question/11523272.html</p>
http://zhidao.baixing.com/question/11523277.html</p>
http://zhidao.baixing.com/question/11523280.html</p>
http://zhidao.baixing.com/question/11523281.html</p>
http://zhidao.baixing.com/question/11523282.html</p>
http://zhidao.baixing.com/question/11523287.html</p>
http://zhidao.baixing.com/question/11523292.html</p>
http://zhidao.baixing.com/question/11523298.html</p>
http://zhidao.baixing.com/question/11523299.html</p>
http://zhidao.baixing.com/question/11523301.html</p>
http://zhidao.baixing.com/question/11523304.html</p>
http://zhidao.baixing.com/question/11523305.html</p>
http://zhidao.baixing.com/question/11523310.html</p>
http://zhidao.baixing.com/question/11523312.html</p>
http://zhidao.baixing.com/question/11523316.html</p>
http://zhidao.baixing.com/question/11523320.html</p>
http://zhidao.baixing.com/question/11523323.html</p>
http://zhidao.baixing.com/question/11523325.html</p>
http://zhidao.baixing.com/question/11523328.html</p>
http://zhidao.baixing.com/question/11523330.html</p>
http://zhidao.baixing.com/question/11523333.html</p>
http://zhidao.baixing.com/question/11523337.html</p>
http://zhidao.baixing.com/question/11523341.html</p>
http://zhidao.baixing.com/question/11523345.html</p>
http://zhidao.baixing.com/question/11523351.html</p>
http://zhidao.baixing.com/question/11523355.html</p>
http://zhidao.baixing.com/question/11523358.html</p>
http://zhidao.baixing.com/question/11523360.html</p>
http://zhidao.baixing.com/question/11523363.html</p>
http://zhidao.baixing.com/question/11523367.html</p>
http://zhidao.baixing.com/question/11523371.html</p>
http://zhidao.baixing.com/question/11523375.html</p>
http://zhidao.baixing.com/question/11523378.html</p>
http://zhidao.baixing.com/question/11523380.html</p>
http://zhidao.baixing.com/question/11523383.html</p>
http://zhidao.baixing.com/question/11523386.html</p>
http://zhidao.baixing.com/question/11523389.html</p>
http://zhidao.baixing.com/question/11523394.html</p>
http://zhidao.baixing.com/question/11523396.html</p>
http://zhidao.baixing.com/question/11523399.html</p>
http://zhidao.baixing.com/question/11523400.html</p>
http://zhidao.baixing.com/question/11523404.html</p>
http://zhidao.baixing.com/question/11523406.html</p>
http://zhidao.baixing.com/question/11523412.html</p>
http://zhidao.baixing.com/question/11523418.html</p>
http://zhidao.baixing.com/question/11523422.html</p>
http://zhidao.baixing.com/question/11523425.html</p>
http://zhidao.baixing.com/question/11523428.html</p>
http://zhidao.baixing.com/question/11523430.html</p>
http://zhidao.baixing.com/question/11523432.html</p>
http://zhidao.baixing.com/question/11523437.html</p>
http://zhidao.baixing.com/question/11523441.html</p>
http://zhidao.baixing.com/question/11523445.html</p>
http://zhidao.baixing.com/question/11523446.html</p>
http://zhidao.baixing.com/question/11523449.html</p>
http://zhidao.baixing.com/question/11523452.html</p>
http://zhidao.baixing.com/question/11523454.html</p>
http://zhidao.baixing.com/question/11523460.html</p>
http://zhidao.baixing.com/question/11523461.html</p>
http://zhidao.baixing.com/question/11523468.html</p>
http://zhidao.baixing.com/question/11523472.html</p>
http://zhidao.baixing.com/question/11523475.html</p>
http://zhidao.baixing.com/question/11523478.html</p>
http://zhidao.baixing.com/question/11523481.html</p>
http://zhidao.baixing.com/question/11523482.html</p>
http://zhidao.baixing.com/question/11523485.html</p>
http://zhidao.baixing.com/question/11523487.html</p>
http://zhidao.baixing.com/question/11523492.html</p>
http://zhidao.baixing.com/question/11523494.html</p>
http://zhidao.baixing.com/question/11523500.html</p>
http://zhidao.baixing.com/question/11523501.html</p>
http://zhidao.baixing.com/question/11523502.html</p>
http://zhidao.baixing.com/question/11523506.html</p>
http://zhidao.baixing.com/question/11523509.html</p>
http://zhidao.baixing.com/question/11523516.html</p>
http://zhidao.baixing.com/question/11523521.html</p>
http://zhidao.baixing.com/question/11523525.html</p>
http://zhidao.baixing.com/question/11523530.html</p>
http://zhidao.baixing.com/question/11523533.html</p>
http://zhidao.baixing.com/question/11523534.html</p>
http://zhidao.baixing.com/question/11523537.html</p>
http://zhidao.baixing.com/question/11523539.html</p>
http://zhidao.baixing.com/question/11523541.html</p>
http://zhidao.baixing.com/question/11523543.html</p>
http://zhidao.baixing.com/question/11523547.html</p>
http://zhidao.baixing.com/question/11523550.html</p>
http://zhidao.baixing.com/question/11523551.html</p>
http://zhidao.baixing.com/question/11523554.html</p>
http://zhidao.baixing.com/question/11523555.html</p>
http://zhidao.baixing.com/question/11523561.html</p>
http://zhidao.baixing.com/question/11523565.html</p>
http://zhidao.baixing.com/question/11523572.html</p>
http://zhidao.baixing.com/question/11523574.html</p>
http://zhidao.baixing.com/question/11523580.html</p>
http://zhidao.baixing.com/question/11523581.html</p>
http://zhidao.baixing.com/question/11523583.html</p>
http://zhidao.baixing.com/question/11523584.html</p>
http://zhidao.baixing.com/question/11523592.html</p>
http://zhidao.baixing.com/question/11523596.html</p>
http://zhidao.baixing.com/question/11523599.html</p>
http://zhidao.baixing.com/question/11523601.html</p>
http://zhidao.baixing.com/question/11523605.html</p>
http://zhidao.baixing.com/question/11523607.html</p>
http://zhidao.baixing.com/question/11523613.html</p>
http://zhidao.baixing.com/question/11523614.html</p>
http://zhidao.baixing.com/question/11523616.html</p>
http://zhidao.baixing.com/question/11523617.html</p>
http://zhidao.baixing.com/question/11523620.html</p>
http://zhidao.baixing.com/question/11523622.html</p>
http://zhidao.baixing.com/question/11523623.html</p>
http://zhidao.baixing.com/question/11523624.html</p>
http://zhidao.baixing.com/question/11523625.html</p>
http://zhidao.baixing.com/question/11523630.html</p>
http://zhidao.baixing.com/question/11523633.html</p>
http://zhidao.baixing.com/question/11523637.html</p>
http://zhidao.baixing.com/question/11523638.html</p>
http://zhidao.baixing.com/question/11523640.html</p>
http://zhidao.baixing.com/question/11523641.html</p>
http://zhidao.baixing.com/question/11523642.html</p>
http://zhidao.baixing.com/question/11523643.html</p>
http://zhidao.baixing.com/question/11523646.html</p>
http://zhidao.baixing.com/question/11523648.html</p>
http://zhidao.baixing.com/question/11523651.html</p>
http://zhidao.baixing.com/question/11523653.html</p>
http://zhidao.baixing.com/question/11523655.html</p>
http://zhidao.baixing.com/question/11523656.html</p>
http://zhidao.baixing.com/question/11523657.html</p>
http://zhidao.baixing.com/question/11523660.html</p>
http://zhidao.baixing.com/question/11523661.html</p>
http://zhidao.baixing.com/question/11523665.html</p>
http://zhidao.baixing.com/question/11523666.html</p>
http://zhidao.baixing.com/question/11523669.html</p>
http://zhidao.baixing.com/question/11523670.html</p>
http://zhidao.baixing.com/question/11523673.html</p>
http://zhidao.baixing.com/question/11523676.html</p>
http://zhidao.baixing.com/question/11523678.html</p>
http://zhidao.baixing.com/question/11523680.html</p>
http://zhidao.baixing.com/question/11523685.html</p>
http://zhidao.baixing.com/question/11523689.html</p>
http://zhidao.baixing.com/question/11523693.html</p>
http://zhidao.baixing.com/question/11523697.html</p>
http://zhidao.baixing.com/question/11523700.html</p>
http://zhidao.baixing.com/question/11523707.html</p>
http://zhidao.baixing.com/question/11523711.html</p>
http://zhidao.baixing.com/question/11523716.html</p>
http://zhidao.baixing.com/question/11523719.html</p>
http://zhidao.baixing.com/question/11523722.html</p>
http://zhidao.baixing.com/question/11523724.html</p>
http://zhidao.baixing.com/question/11523726.html</p>
http://zhidao.baixing.com/question/11523728.html</p>
http://zhidao.baixing.com/question/11523729.html</p>
http://zhidao.baixing.com/question/11523736.html</p>
http://zhidao.baixing.com/question/11523740.html</p>
http://zhidao.baixing.com/question/11523742.html</p>
http://zhidao.baixing.com/question/11523744.html</p>
http://zhidao.baixing.com/question/11523746.html</p>
http://zhidao.baixing.com/question/11523748.html</p>
http://zhidao.baixing.com/question/11523753.html</p>
http://zhidao.baixing.com/question/11523756.html</p>
http://zhidao.baixing.com/question/11523757.html</p>
http://zhidao.baixing.com/question/11523758.html</p>
http://zhidao.baixing.com/question/11523759.html</p>
http://zhidao.baixing.com/question/11523761.html</p>
http://zhidao.baixing.com/question/11523763.html</p>
http://zhidao.baixing.com/question/11523765.html</p>
http://zhidao.baixing.com/question/11523767.html</p>
http://zhidao.baixing.com/question/11523770.html</p>
http://zhidao.baixing.com/question/11523772.html</p>
http://zhidao.baixing.com/question/11523778.html</p>
http://zhidao.baixing.com/question/11523779.html</p>
http://zhidao.baixing.com/question/11523780.html</p>
http://zhidao.baixing.com/question/11523783.html</p>
http://zhidao.baixing.com/question/11523787.html</p>
http://zhidao.baixing.com/question/11523791.html</p>
http://zhidao.baixing.com/question/11523792.html</p>
http://zhidao.baixing.com/question/11523794.html</p>
http://zhidao.baixing.com/question/11523795.html</p>
http://zhidao.baixing.com/question/11523796.html</p>
http://zhidao.baixing.com/question/11523798.html</p>
http://zhidao.baixing.com/question/11523802.html</p>
http://zhidao.baixing.com/question/11523804.html</p>
http://zhidao.baixing.com/question/11523805.html</p>
http://zhidao.baixing.com/question/11523807.html</p>
http://zhidao.baixing.com/question/11523812.html</p>
http://zhidao.baixing.com/question/11523816.html</p>
http://zhidao.baixing.com/question/11523819.html</p>
http://zhidao.baixing.com/question/11523820.html</p>
http://zhidao.baixing.com/question/11523822.html</p>
http://zhidao.baixing.com/question/11523825.html</p>
http://zhidao.baixing.com/question/11523826.html</p>
http://zhidao.baixing.com/question/11523828.html</p>
http://zhidao.baixing.com/question/11523830.html</p>
http://zhidao.baixing.com/question/11523832.html</p>
http://zhidao.baixing.com/question/11523834.html</p>
http://zhidao.baixing.com/question/11523835.html</p>
http://zhidao.baixing.com/question/11523839.html</p>
http://zhidao.baixing.com/question/11523841.html</p>
http://zhidao.baixing.com/question/11523845.html</p>
http://zhidao.baixing.com/question/11523848.html</p>
http://zhidao.baixing.com/question/11523849.html</p>
http://zhidao.baixing.com/question/11523850.html</p>
http://zhidao.baixing.com/question/11523851.html</p>
http://zhidao.baixing.com/question/11523859.html</p>
http://zhidao.baixing.com/question/11523861.html</p>
http://zhidao.baixing.com/question/11523863.html</p>
http://zhidao.baixing.com/question/11523864.html</p>
http://zhidao.baixing.com/question/11523865.html</p>
http://zhidao.baixing.com/question/11523867.html</p>
http://zhidao.baixing.com/question/11523869.html</p>
http://zhidao.baixing.com/question/11523874.html</p>
http://zhidao.baixing.com/question/11523879.html</p>
http://zhidao.baixing.com/question/11523884.html</p>
http://zhidao.baixing.com/question/11523885.html</p>
http://zhidao.baixing.com/question/11523887.html</p>
http://zhidao.baixing.com/question/11523889.html</p>
http://zhidao.baixing.com/question/11523891.html</p>
http://zhidao.baixing.com/question/11523894.html</p>
http://zhidao.baixing.com/question/11523895.html</p>
http://zhidao.baixing.com/question/11523897.html</p>
http://zhidao.baixing.com/question/11523899.html</p>
http://zhidao.baixing.com/question/11523900.html</p>
http://zhidao.baixing.com/question/11523905.html</p>
http://zhidao.baixing.com/question/11523907.html</p>
http://zhidao.baixing.com/question/11523911.html</p>
http://zhidao.baixing.com/question/11523917.html</p>
http://zhidao.baixing.com/question/11523919.html</p>
http://zhidao.baixing.com/question/11523922.html</p>
http://zhidao.baixing.com/question/11523923.html</p>
http://zhidao.baixing.com/question/11523925.html</p>
http://zhidao.baixing.com/question/11523928.html</p>
http://zhidao.baixing.com/question/11523931.html</p>
http://zhidao.baixing.com/question/11523932.html</p>
http://zhidao.baixing.com/question/11523935.html</p>
http://zhidao.baixing.com/question/11523939.html</p>
http://zhidao.baixing.com/question/11523942.html</p>
http://zhidao.baixing.com/question/11523945.html</p>
http://zhidao.baixing.com/question/11523947.html</p>
http://zhidao.baixing.com/question/11523948.html</p>
http://zhidao.baixing.com/question/11523950.html</p>
http://zhidao.baixing.com/question/11523958.html</p>
http://zhidao.baixing.com/question/11523965.html</p>
http://zhidao.baixing.com/question/11523970.html</p>
http://zhidao.baixing.com/question/11523975.html</p>
http://zhidao.baixing.com/question/11523977.html</p>
http://zhidao.baixing.com/question/11523979.html</p>
http://zhidao.baixing.com/question/11523980.html</p>
http://zhidao.baixing.com/question/11523982.html</p>
http://zhidao.baixing.com/question/11523988.html</p>
http://zhidao.baixing.com/question/11523993.html</p>
http://zhidao.baixing.com/question/11523997.html</p>
http://zhidao.baixing.com/question/11523998.html</p>
http://zhidao.baixing.com/question/11524005.html</p>
http://zhidao.baixing.com/question/11524008.html</p>
http://zhidao.baixing.com/question/11524009.html</p>
http://zhidao.baixing.com/question/11524017.html</p>
http://zhidao.baixing.com/question/11524023.html</p>
http://zhidao.baixing.com/question/11524025.html</p>
http://zhidao.baixing.com/question/11524029.html</p>
http://zhidao.baixing.com/question/11524031.html</p>
http://zhidao.baixing.com/question/11524032.html</p>
http://zhidao.baixing.com/question/11524033.html</p>
http://zhidao.baixing.com/question/11524035.html</p>
http://zhidao.baixing.com/question/11524040.html</p>
http://zhidao.baixing.com/question/11524045.html</p>
http://zhidao.baixing.com/question/11524048.html</p>
http://zhidao.baixing.com/question/11524053.html</p>
http://zhidao.baixing.com/question/11524055.html</p>
http://zhidao.baixing.com/question/11524059.html</p>
http://zhidao.baixing.com/question/11524063.html</p>
http://zhidao.baixing.com/question/11524065.html</p>
http://zhidao.baixing.com/question/11524067.html</p>
http://zhidao.baixing.com/question/11524069.html</p>
http://zhidao.baixing.com/question/11524071.html</p>
http://zhidao.baixing.com/question/11524077.html</p>
http://zhidao.baixing.com/question/11524082.html</p>
http://zhidao.baixing.com/question/11524084.html</p>
http://zhidao.baixing.com/question/11524087.html</p>
http://zhidao.baixing.com/question/11524088.html</p>
http://zhidao.baixing.com/question/11524089.html</p>
http://zhidao.baixing.com/question/11524092.html</p>
http://zhidao.baixing.com/question/11524094.html</p>
http://zhidao.baixing.com/question/11524097.html</p>
http://zhidao.baixing.com/question/11524098.html</p>
http://zhidao.baixing.com/question/11524099.html</p>
http://zhidao.baixing.com/question/11524100.html</p>
http://zhidao.baixing.com/question/11524104.html</p>
http://zhidao.baixing.com/question/11524106.html</p>
http://zhidao.baixing.com/question/11524113.html</p>
http://zhidao.baixing.com/question/11524114.html</p>
http://zhidao.baixing.com/question/11524115.html</p>
http://zhidao.baixing.com/question/11524118.html</p>
http://zhidao.baixing.com/question/11524121.html</p>
http://zhidao.baixing.com/question/11524131.html</p>
http://zhidao.baixing.com/question/11524133.html</p>
http://zhidao.baixing.com/question/11524136.html</p>
http://zhidao.baixing.com/question/11524137.html</p>
http://zhidao.baixing.com/question/11524139.html</p>
http://zhidao.baixing.com/question/11524141.html</p>
http://zhidao.baixing.com/question/11524142.html</p>
http://zhidao.baixing.com/question/11524144.html</p>
http://zhidao.baixing.com/question/11524149.html</p>
http://zhidao.baixing.com/question/11524151.html</p>
http://zhidao.baixing.com/question/11524156.html</p>
http://zhidao.baixing.com/question/11524159.html</p>
http://zhidao.baixing.com/question/11524160.html</p>
http://zhidao.baixing.com/question/11524162.html</p>
http://zhidao.baixing.com/question/11524163.html</p>
http://zhidao.baixing.com/question/11524165.html</p>
http://zhidao.baixing.com/question/11524169.html</p>
http://zhidao.baixing.com/question/11524172.html</p>
http://zhidao.baixing.com/question/11524177.html</p>
http://zhidao.baixing.com/question/11524179.html</p>
http://zhidao.baixing.com/question/11524183.html</p>
http://zhidao.baixing.com/question/11524186.html</p>
http://zhidao.baixing.com/question/11524188.html</p>
http://zhidao.baixing.com/question/11524189.html</p>
http://zhidao.baixing.com/question/11524193.html</p>
http://zhidao.baixing.com/question/11524195.html</p>
http://zhidao.baixing.com/question/11524196.html</p>
http://zhidao.baixing.com/question/11524197.html</p>
http://zhidao.baixing.com/question/11524199.html</p>
http://zhidao.baixing.com/question/11524200.html</p>
http://zhidao.baixing.com/question/11524204.html</p>
http://zhidao.baixing.com/question/11524206.html</p>
http://zhidao.baixing.com/question/11524208.html</p>
http://zhidao.baixing.com/question/11524210.html</p>
http://zhidao.baixing.com/question/11524211.html</p>
http://zhidao.baixing.com/question/11524213.html</p>
http://zhidao.baixing.com/question/11524216.html</p>
http://zhidao.baixing.com/question/11524217.html</p>
http://zhidao.baixing.com/question/11524218.html</p>
http://zhidao.baixing.com/question/11524220.html</p>
http://zhidao.baixing.com/question/11524221.html</p>
http://zhidao.baixing.com/question/11524222.html</p>
http://zhidao.baixing.com/question/11524224.html</p>
http://zhidao.baixing.com/question/11524227.html</p>
http://zhidao.baixing.com/question/11524228.html</p>
http://zhidao.baixing.com/question/11524229.html</p>
http://zhidao.baixing.com/question/11524230.html</p>
http://zhidao.baixing.com/question/11524231.html</p>
http://zhidao.baixing.com/question/11524233.html</p>
http://zhidao.baixing.com/question/11524235.html</p>
http://zhidao.baixing.com/question/11524238.html</p>
http://zhidao.baixing.com/question/11524239.html</p>
http://zhidao.baixing.com/question/11524242.html</p>
http://zhidao.baixing.com/question/11524243.html</p>
http://zhidao.baixing.com/question/11524245.html</p>
http://zhidao.baixing.com/question/11524246.html</p>
http://zhidao.baixing.com/question/11524247.html</p>
http://zhidao.baixing.com/question/11524248.html</p>
http://zhidao.baixing.com/question/11524251.html</p>
http://zhidao.baixing.com/question/11524255.html</p>
http://zhidao.baixing.com/question/11524259.html</p>
http://zhidao.baixing.com/question/11524260.html</p>
http://zhidao.baixing.com/question/11524262.html</p>
http://zhidao.baixing.com/question/11524264.html</p>
http://zhidao.baixing.com/question/11524266.html</p>
http://zhidao.baixing.com/question/11524267.html</p>
http://zhidao.baixing.com/question/11524268.html</p>
http://zhidao.baixing.com/question/11524269.html</p>
http://zhidao.baixing.com/question/11524271.html</p>
http://zhidao.baixing.com/question/11524272.html</p>
http://zhidao.baixing.com/question/11524273.html</p>
http://zhidao.baixing.com/question/11524274.html</p>
http://zhidao.baixing.com/question/11524277.html</p>
http://zhidao.baixing.com/question/11524278.html</p>
http://zhidao.baixing.com/question/11524279.html</p>
http://zhidao.baixing.com/question/11524280.html</p>
http://zhidao.baixing.com/question/11524281.html</p>
http://zhidao.baixing.com/question/11524282.html</p>
http://zhidao.baixing.com/question/11524283.html</p>
http://zhidao.baixing.com/question/11524285.html</p>
http://zhidao.baixing.com/question/11524288.html</p>
http://zhidao.baixing.com/question/11524289.html</p>
http://zhidao.baixing.com/question/11524290.html</p>
http://zhidao.baixing.com/question/11524291.html</p>
http://zhidao.baixing.com/question/11524294.html</p>
http://zhidao.baixing.com/question/11524295.html</p>
http://zhidao.baixing.com/question/11524297.html</p>
http://zhidao.baixing.com/question/11524298.html</p>
http://zhidao.baixing.com/question/11524299.html</p>
http://zhidao.baixing.com/question/11524301.html</p>
http://zhidao.baixing.com/question/11524302.html</p>
http://zhidao.baixing.com/question/11524304.html</p>
http://zhidao.baixing.com/question/11524305.html</p>
http://zhidao.baixing.com/question/11524308.html</p>
http://zhidao.baixing.com/question/11524309.html</p>
http://zhidao.baixing.com/question/11524312.html</p>
http://zhidao.baixing.com/question/11524313.html</p>
http://zhidao.baixing.com/question/11524314.html</p>
http://zhidao.baixing.com/question/11524315.html</p>
http://zhidao.baixing.com/question/11524316.html</p>
http://zhidao.baixing.com/question/11524317.html</p>
http://zhidao.baixing.com/question/11524319.html</p>
http://zhidao.baixing.com/question/11524320.html</p>
http://zhidao.baixing.com/question/11524321.html</p>
http://zhidao.baixing.com/question/11524322.html</p>
http://zhidao.baixing.com/question/11524323.html</p>
http://zhidao.baixing.com/question/11524324.html</p>
http://zhidao.baixing.com/question/11524325.html</p>
http://zhidao.baixing.com/question/11524328.html</p>
http://zhidao.baixing.com/question/11524329.html</p>
http://zhidao.baixing.com/question/11524330.html</p>
http://zhidao.baixing.com/question/11524332.html</p>
http://zhidao.baixing.com/question/11524334.html</p>
http://zhidao.baixing.com/question/11524336.html</p>
http://zhidao.baixing.com/question/11524338.html</p>
http://zhidao.baixing.com/question/11524339.html</p>
http://zhidao.baixing.com/question/11524341.html</p>
http://zhidao.baixing.com/question/11524342.html</p>
http://zhidao.baixing.com/question/11524343.html</p>
http://zhidao.baixing.com/question/11524345.html</p>
http://zhidao.baixing.com/question/11524347.html</p>
http://zhidao.baixing.com/question/11524349.html</p>
http://zhidao.baixing.com/question/11524350.html</p>
http://zhidao.baixing.com/question/11524351.html</p>
http://zhidao.baixing.com/question/11524352.html</p>
http://zhidao.baixing.com/question/11524353.html</p>
http://zhidao.baixing.com/question/11524354.html</p>
http://zhidao.baixing.com/question/11524356.html</p>
http://zhidao.baixing.com/question/11524357.html</p>
http://zhidao.baixing.com/question/11524358.html</p>
http://zhidao.baixing.com/question/11524359.html</p>
http://zhidao.baixing.com/question/11524361.html</p>
http://zhidao.baixing.com/question/11524362.html</p>
http://zhidao.baixing.com/question/11524364.html</p>
http://zhidao.baixing.com/question/11524366.html</p>
http://zhidao.baixing.com/question/11524370.html</p>
http://zhidao.baixing.com/question/11524373.html</p>
http://zhidao.baixing.com/question/11524374.html</p>
http://zhidao.baixing.com/question/11524375.html</p>
http://zhidao.baixing.com/question/11524376.html</p>
http://zhidao.baixing.com/question/11524377.html</p>
http://zhidao.baixing.com/question/11524378.html</p>
http://zhidao.baixing.com/question/11524380.html</p>
http://zhidao.baixing.com/question/11524381.html</p>
http://zhidao.baixing.com/question/11524382.html</p>
http://zhidao.baixing.com/question/11524385.html</p>
http://zhidao.baixing.com/question/11524387.html</p>
http://zhidao.baixing.com/question/11524388.html</p>
http://zhidao.baixing.com/question/11524389.html</p>
http://zhidao.baixing.com/question/11524390.html</p>
http://zhidao.baixing.com/question/11524391.html</p>
http://zhidao.baixing.com/question/11524392.html</p>
http://zhidao.baixing.com/question/11524393.html</p>
http://zhidao.baixing.com/question/11524394.html</p>
http://zhidao.baixing.com/question/11524395.html</p>
http://zhidao.baixing.com/question/11524397.html</p>
http://zhidao.baixing.com/question/11524398.html</p>
http://zhidao.baixing.com/question/11524400.html</p>
http://zhidao.baixing.com/question/11524401.html</p>
http://zhidao.baixing.com/question/11524403.html</p>
http://zhidao.baixing.com/question/11524404.html</p>
http://zhidao.baixing.com/question/11524406.html</p>
http://zhidao.baixing.com/question/11524407.html</p>
http://zhidao.baixing.com/question/11524408.html</p>
http://zhidao.baixing.com/question/11524409.html</p>
http://zhidao.baixing.com/question/11524410.html</p>
http://zhidao.baixing.com/question/11524411.html</p>
<img src ="http://www.cppblog.com/sunicdavy/aggbug/217894.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2021-12-27 19:04 <a href="http://www.cppblog.com/sunicdavy/archive/2021/12/27/217894.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>但是GPU的性能依然还是DrawCall优化那一套</title><link>http://www.cppblog.com/sunicdavy/archive/2021/12/27/217892.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Mon, 27 Dec 2021 11:01:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2021/12/27/217892.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/217892.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2021/12/27/217892.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/217892.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/217892.html</trackback:ping><description><![CDATA[ Entitas的ECS系统

1. 本来在一个对象中添加一个类字段的过程，ECS需要添加一个类代表Component，并且代码生成。

这个字段一般用于描述对象的资源，处理显示的GameObject， 表示对象的类型等。



2. 本来一个对象的业务逻辑处理过程直接用方法解决的， ECS需要新加一个System，而操作对象需要使用Filter或Group查询获得。



3. 一系列的操作， 需要拆分为多个System和Component拆分处理。如果System顺序不对， 会造成一些诡异的bug。



4. Component不仅仅是Model承载体， 也可以是参数的数据结构。参数Component通过Entity传递到System处理。 例如： 通过ECS创建一个方块的过程，使用CreateTileComponent，包含创建Tile的位置， 创建Entity并添加CreateTileComponent， 在CreateTileSystem中处理就创建了Tile，处理完成时， 需要将传入的Entity.Destroy掉。



6. Entity上修改Component的过程， 会触发事件。修改的过程需要使用RelaceXXX，XXX表示组件名。组件可以频繁修改， 不用担心添加和删除组件过程的性能， Entitas底层处理性能只相当于指针赋值的性能。



ECS像什么？

1. ECS中的System类似触发器系统（Event-Condition-Action），其中，Event对应Entitas的GetTrigger+Collector，表示触发事件。Condition对应Filter表示在事件来源对象中找到需要的对象。 Action对应Execute，表示实际的操作。

2. ECS中的Component类似不用lua扩展的Redis或者不用存储过程的MySQL， 纯粹纯数据， 而不能对数据有任何封装操作。没有lua和存储过程支持的db写起来还是比较费劲的，但ECS就是那么的纯。



3. ECS中的Entity很尴尬，因为Component是按类别连续存储的以保证性能。 逻辑又需要Entity组合成逻辑需要的复合对象。 两边都要照顾，所以这种设计就让代码量巨增，可读性下降。





ECS企图用一套框架灭掉设计模式

1. 单件（Singleton）在Entitas用Unique标签标记Component， 在Context中就是唯一的， 其实也就是Singleton。



2. ECS干掉了传统的工厂模式，底层统一对对象（Entity）和属性（Component）统一管理。需要按Component中的值找回Entity时， 可以使用EntityIndex。



3. Entity携带不同的组件时，整个创建和销毁过程被记录并恢复，其实就是Command模式



ECS适合做UI框架（类似MVVM，MVC,MVP）么？

ECS不是专用的UI框架，但是可以对不同系统和数据间解耦。传统代码中数据修改后的Callback，ECS也可以用Listener做， 但Listener因为能保存数据， 就需要用Component保存。 所以你需要面对的是，一个Button，响应创建一个参数用的Component和System，还要为数据改变写一套ListenComponent和Listener处理的System，酸爽吧？



Minecraft适合ECS来做么？

可以，性能应该能提升不少，但是代码会更繁琐，特别像Java这种啰嗦语言配上ECS这种啰嗦框架，估计代码量翻翻还是很轻松的。MC属于特殊类型的游戏，适合特殊领域特别优化，也就是专门为方块做出特别的设计来做优化。ECS属于通用框架，即便性能OK，但是代码未必能有良好的可读性。



体量小的游戏适合用ECS来做么？

可以，但不建议。特别是只有几个人维护的工程，贸然上ECS系统，会让系统变的极为复杂。当然你会说，如果开发到后期，传统开发模式会导致代码会乱，ECS会好些吧。掌握ECS也不是一天两天的事情，不熟悉ECS的程序员设计出来的系统获得的优势可能还不如用传统设计方法好呢。

架构解决的是人的问题， 人都有问题，用什么框架都没办法。



到底什么项目适合用ECS？

1. 大量的小个体不断的生成和销毁以及显示，例如： 攻城战中，要体现每个角色的移动，战斗。

2. 多于5个人编写核心战斗逻辑。互相协作和模块切分，需要一个大家都能信服的框架，ECS可以选择。



P.S.

不要造ECS的轮子！

很多同学看了ECS基本原理，在没有深入使用过任何ECS系统时马上操刀造轮子。ECS系统确实看起来简单。实际造下来你会发现，性能非常糟糕以及不知道一些逻辑如何用ECS来解决。



总结：

1. ECS确实为性能而生，没有并发加持性能的ECS都是耍流氓，要快就要快到极致。

2. Unity中，ECS并发能扩展CPU的利用率，但是GPU的性能依然还是DrawCall优化那一套，别期望ECS会颠覆Unity，性能也不会快到飞起，关键还是要看具体的项目和人。

3. ECS是万能框架，但不全能。传统架构和设计思想也不是一无是处，熟啥用啥，怎么快怎么来！


https://mip.bmlink.com/wu19870821/news/2611408.html
https://mip.bmlink.com/wu19870821/news/2611409.html
https://mip.bmlink.com/wu19870821/news/2611410.html
https://mip.bmlink.com/wu19870821/news/2611411.html
https://mip.bmlink.com/wu19870821/news/2611412.html
https://mip.bmlink.com/wu19870821/news/2611413.html
https://mip.bmlink.com/wu19870821/news/2611414.html
https://mip.bmlink.com/wu19870821/news/2611415.html
https://mip.bmlink.com/wu19870821/news/2611416.html
https://mip.bmlink.com/wu19870821/news/2611417.html
https://m.bmlink.com/wu19870821/news/2611408.html
https://m.bmlink.com/wu19870821/news/2611409.html
https://m.bmlink.com/wu19870821/news/2611410.html
https://m.bmlink.com/wu19870821/news/2611411.html
https://m.bmlink.com/wu19870821/news/2611412.html
https://m.bmlink.com/wu19870821/news/2611413.html
https://m.bmlink.com/wu19870821/news/2611414.html
https://m.bmlink.com/wu19870821/news/2611415.html
https://m.bmlink.com/wu19870821/news/2611416.html
https://m.bmlink.com/wu19870821/news/2611417.html
https://wu19870821.bmlink.com/news/2611408.html
https://wu19870821.bmlink.com/news/2611409.html
https://wu19870821.bmlink.com/news/2611410.html
https://wu19870821.bmlink.com/news/2611411.html
https://wu19870821.bmlink.com/news/2611412.html
https://wu19870821.bmlink.com/news/2611413.html
https://wu19870821.bmlink.com/news/2611414.html
https://wu19870821.bmlink.com/news/2611415.html
https://wu19870821.bmlink.com/news/2611416.html
https://wu19870821.bmlink.com/news/2611417.html
https://www.bmlink.com/wu19870821/news/2611408.html
https://www.bmlink.com/wu19870821/news/2611409.html
https://www.bmlink.com/wu19870821/news/2611410.html
https://www.bmlink.com/wu19870821/news/2611411.html
https://www.bmlink.com/wu19870821/news/2611412.html
https://www.bmlink.com/wu19870821/news/2611413.html
https://www.bmlink.com/wu19870821/news/2611414.html
https://www.bmlink.com/wu19870821/news/2611415.html
https://www.bmlink.com/wu19870821/news/2611416.html
https://www.bmlink.com/wu19870821/news/2611417.html
https://mip.bmlink.com/chaoweifensuiji/news/2611407.html
https://mip.bmlink.com/chaoweifensuiji/news/2611406.html
https://mip.bmlink.com/chaoweifensuiji/news/2558756.html
https://mip.bmlink.com/chaoweifensuiji/news/2558753.html
https://mip.bmlink.com/chaoweifensuiji/news/2558748.html
https://mip.bmlink.com/chaoweifensuiji/news/2558743.html
https://mip.bmlink.com/chaoweifensuiji/news/2558740.html
https://mip.bmlink.com/chaoweifensuiji/news/2558737.html
https://mip.bmlink.com/chaoweifensuiji/news/2558731.html
https://m.bmlink.com/chaoweifensuiji/news/2611407.html
https://m.bmlink.com/chaoweifensuiji/news/2611406.html
https://m.bmlink.com/chaoweifensuiji/news/2558756.html
https://m.bmlink.com/chaoweifensuiji/news/2558753.html
https://m.bmlink.com/chaoweifensuiji/news/2558748.html
https://m.bmlink.com/chaoweifensuiji/news/2558743.html
https://m.bmlink.com/chaoweifensuiji/news/2558740.html
https://m.bmlink.com/chaoweifensuiji/news/2558737.html
https://m.bmlink.com/chaoweifensuiji/news/2558731.html
https://chaoweifensuiji.bmlink.com/news/2611407.html
https://chaoweifensuiji.bmlink.com/news/2611406.html
https://chaoweifensuiji.bmlink.com/news/2558756.html
https://chaoweifensuiji.bmlink.com/news/2558753.html
https://chaoweifensuiji.bmlink.com/news/2558748.html
https://chaoweifensuiji.bmlink.com/news/2558743.html
https://chaoweifensuiji.bmlink.com/news/2558740.html
https://chaoweifensuiji.bmlink.com/news/2558737.html
https://chaoweifensuiji.bmlink.com/news/2558731.html
https://www.bmlink.com/chaoweifensuiji/news/2611407.html
https://www.bmlink.com/chaoweifensuiji/news/2611406.html
https://www.bmlink.com/chaoweifensuiji/news/2558756.html
https://www.bmlink.com/chaoweifensuiji/news/2558753.html
https://www.bmlink.com/chaoweifensuiji/news/2558748.html
https://www.bmlink.com/chaoweifensuiji/news/2558743.html
https://www.bmlink.com/chaoweifensuiji/news/2558740.html
https://www.bmlink.com/chaoweifensuiji/news/2558737.html
https://www.bmlink.com/chaoweifensuiji/news/2558731.html
https://mip.bmlink.com/towercrane/news/2541940.html
https://mip.bmlink.com/towercrane/news/2541945.html
https://mip.bmlink.com/towercrane/news/2541950.html
https://mip.bmlink.com/towercrane/news/2541966.html
https://mip.bmlink.com/towercrane/news/2541991.html
https://mip.bmlink.com/towercrane/news/2541992.html
https://mip.bmlink.com/towercrane/news/2541993.html
https://mip.bmlink.com/towercrane/news/2541994.html
https://mip.bmlink.com/towercrane/news/2541995.html
https://m.bmlink.com/towercrane/news/2541940.html
https://m.bmlink.com/towercrane/news/2541945.html
https://m.bmlink.com/towercrane/news/2541950.html
https://m.bmlink.com/towercrane/news/2541966.html
https://m.bmlink.com/towercrane/news/2541991.html
https://m.bmlink.com/towercrane/news/2541992.html
https://m.bmlink.com/towercrane/news/2541993.html
https://m.bmlink.com/towercrane/news/2541994.html
https://m.bmlink.com/towercrane/news/2541995.html
https://towercrane.bmlink.com/news/2541940.html
https://towercrane.bmlink.com/news/2541945.html
https://towercrane.bmlink.com/news/2541950.html
https://towercrane.bmlink.com/news/2541966.html
https://towercrane.bmlink.com/news/2541991.html
https://towercrane.bmlink.com/news/2541992.html
https://towercrane.bmlink.com/news/2541993.html
https://towercrane.bmlink.com/news/2541994.html
https://towercrane.bmlink.com/news/2541995.html
https://www.bmlink.com/towercrane/news/2541940.html
https://www.bmlink.com/towercrane/news/2541945.html
https://www.bmlink.com/towercrane/news/2541950.html
https://www.bmlink.com/towercrane/news/2541966.html
https://www.bmlink.com/towercrane/news/2541991.html
https://www.bmlink.com/towercrane/news/2541992.html
https://www.bmlink.com/towercrane/news/2541993.html
https://www.bmlink.com/towercrane/news/2541994.html
https://www.bmlink.com/towercrane/news/2541995.html
https://mip.bmlink.com/xxmjhw888/news/2611429.html
https://mip.bmlink.com/xxmjhw888/news/2611428.html
https://mip.bmlink.com/xxmjhw888/news/2611427.html
https://mip.bmlink.com/xxmjhw888/news/2611426.html
https://mip.bmlink.com/xxmjhw888/news/2611425.html
https://mip.bmlink.com/xxmjhw888/news/2611424.html
https://mip.bmlink.com/xxmjhw888/news/2611423.html
https://mip.bmlink.com/xxmjhw888/news/2611422.html
https://mip.bmlink.com/xxmjhw888/news/2611421.html
https://mip.bmlink.com/xxmjhw888/news/2611420.html
https://mip.bmlink.com/xxmjhw888/news/2611419.html
https://mip.bmlink.com/xxmjhw888/news/2611418.html
https://m.bmlink.com/xxmjhw888/news/2611429.html
https://m.bmlink.com/xxmjhw888/news/2611428.html
https://m.bmlink.com/xxmjhw888/news/2611427.html
https://m.bmlink.com/xxmjhw888/news/2611426.html
https://m.bmlink.com/xxmjhw888/news/2611425.html
https://m.bmlink.com/xxmjhw888/news/2611424.html
https://m.bmlink.com/xxmjhw888/news/2611423.html
https://m.bmlink.com/xxmjhw888/news/2611422.html
https://m.bmlink.com/xxmjhw888/news/2611421.html
https://m.bmlink.com/xxmjhw888/news/2611420.html
https://m.bmlink.com/xxmjhw888/news/2611419.html
https://m.bmlink.com/xxmjhw888/news/2611418.html
https://xxmjhw888.bmlink.com/news/2611429.html
https://xxmjhw888.bmlink.com/news/2611428.html
https://xxmjhw888.bmlink.com/news/2611427.html
https://xxmjhw888.bmlink.com/news/2611426.html
https://xxmjhw888.bmlink.com/news/2611425.html
https://xxmjhw888.bmlink.com/news/2611424.html
https://xxmjhw888.bmlink.com/news/2611423.html
https://xxmjhw888.bmlink.com/news/2611422.html
https://xxmjhw888.bmlink.com/news/2611421.html
https://xxmjhw888.bmlink.com/news/2611420.html
https://xxmjhw888.bmlink.com/news/2611419.html
https://xxmjhw888.bmlink.com/news/2611418.html
https://www.bmlink.com/xxmjhw888/news/2611429.html
https://www.bmlink.com/xxmjhw888/news/2611428.html
https://www.bmlink.com/xxmjhw888/news/2611427.html
https://www.bmlink.com/xxmjhw888/news/2611426.html
https://www.bmlink.com/xxmjhw888/news/2611425.html
https://www.bmlink.com/xxmjhw888/news/2611424.html
https://www.bmlink.com/xxmjhw888/news/2611423.html
https://www.bmlink.com/xxmjhw888/news/2611422.html
https://www.bmlink.com/xxmjhw888/news/2611421.html
https://www.bmlink.com/xxmjhw888/news/2611420.html
https://www.bmlink.com/xxmjhw888/news/2611419.html
https://www.bmlink.com/xxmjhw888/news/2611418.html
https://www.ixueyi.com/qinggan/a_Tl9sM38K.html
https://www.ixueyi.com/falv/a_2I2ewPSh.html
https://www.ixueyi.com/falv/a_Y1Un4tSK.html
https://www.ixueyi.com/falv/a_9Q3N5R3R.html
https://www.ixueyi.com/falv/a_A9E8Pvl3.html
https://www.ixueyi.com/falv/a_2jy4G07C.html
https://www.ixueyi.com/falv/a_W5r2as2P.html
https://www.ixueyi.com/falv/a_a20P8p3T.html
https://www.ixueyi.com/falv/a_5jl15mkU.html
https://www.ixueyi.com/falv/a_C646nFN4.html
https://www.ixueyi.com/falv/a_n71xa7a2.html
https://www.ixueyi.com/falv/a_VCxaehV6.html
https://www.ixueyi.com/falv/a_7JhXF2L0.html
https://www.ixueyi.com/falv/a_y5tA5IdR.html
https://www.ixueyi.com/falv/a_qn722hR8.html
https://www.ixueyi.com/falv/a_yX5W85yK.html
https://www.ixueyi.com/renshi/a_r569sY1C.html
https://www.ixueyi.com/renshi/a_472EFKfF.html
https://www.ixueyi.com/renshi/a_umemPeiO.html
https://www.ixueyi.com/renshi/a_9o6T89n3.html
https://www.ixueyi.com/renshi/a_GX26np9Q.html
https://www.ixueyi.com/falv/a_4CAdyV14.html
https://www.ixueyi.com/falv/a_i28019yM.html
https://www.ixueyi.com/falv/a_b2fyO1od.html
https://www.ixueyi.com/falv/a_oq1MYAeY.html
https://www.ixueyi.com/falv/a_XSVSuYNm.html
https://www.ixueyi.com/falv/a_LUxNT8oA.html
https://www.ixueyi.com/falv/a_agNvlmr3.html<img src ="http://www.cppblog.com/sunicdavy/aggbug/217892.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2021-12-27 19:01 <a href="http://www.cppblog.com/sunicdavy/archive/2021/12/27/217892.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>服务器开发语言比较</title><link>http://www.cppblog.com/sunicdavy/archive/2016/01/05/212611.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Tue, 05 Jan 2016 08:51:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2016/01/05/212611.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/212611.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2016/01/05/212611.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/212611.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/212611.html</trackback:ping><description><![CDATA[<p>以下比较的基础都是基于一种编程语言+一定的第三方或者自己编写的网络库和底层进行的，Skynet稍微特殊，但总体比较合适放到比较中来</p> <h1>C#</h1> <p>开发效率：Windows下可以通过VisualStudio进行开发，其他平台可以使用MonoDevelop，非常方便</p> <p>运行效率：JIT的性能优化比较到位，能适应90%性能环境</p> <p>部署便捷性：可以通过交叉编译生成其他平台的可执行文件，通过mono运行可执行文件</p> <p>调试便捷性：VisualStudio和MonoDevelop调试均很方便， 还可远程调试</p> <p>上手度：对C系语言熟悉的几天就可上手</p> <p>热更新：可以通过DLL方式进行</p> <p>Web对接：可做，代码比较啰嗦</p> <p>崩溃处理：可通过try catch捕获错误</p> <p>网络库编写难度：一般，需注意gc问题</p> <p>第三方网络库及框架数量：一般</p> <p>&nbsp;</p> <h1>Golang</h1> <p>开发效率：高</p> <p>运行效率：并发上非常有优势，对CPU利用率比较高，原生运行无虚拟机</p> <p>部署便捷性：一次编译到处运行，无任何运行库依赖</p> <p>调试便捷性：实际操作中，单线程挂接调试器可行， 但变量显示不正确，开发期基本采用日志方式进行查错</p> <p>上手度：语言简单，特性少， 新手1周能贡献代码</p> <p>热更新：无法进行热更新，语言无法编译为DLL，也不支持DLL加载（linux平台的.so加载忽略不计）</p> <p>Web对接：非常方便， 代码精简</p> <p>崩溃处理：崩溃后以命令行方式打印出栈，程序内可以捕获任何崩溃错误并继续运行</p> <p>网络库编写难度：简单，比C socket更简单</p> <p>第三方网络库及框架数量：偏少</p> <p>&nbsp;</p> <h1>Skynet(lua+C)</h1> <p>开发效率：基于动态语言的开发初次写比较快，后期维护和重构会耗费一定的时间在查错上</p> <p>运行效率：基于lua jit的运行效率还是能接受的</p> <p>部署便捷性：方便， 只有底层修改需要重新编译， 大部分时间只用更新lua文件</p> <p>调试便捷性：不是很方便，基于日志方式进行查错</p> <p>上手度：lua语言特性有部分和C系语言有一定差异，基于Actor模型的思想学习，适应需要耗费一定的时间</p> <p>热更新：类似于Erlang，可精确到函数级的热更新</p> <p>Web对接：有一些http支持，通过社区慢慢进行完善</p> <p>崩溃处理：lua天生可以捕获错误</p> <p>网络库编写难度：自带，无需编写</p> <p>第三方网络库及框架数量：通过社区慢慢完善</p> <p>&nbsp;</p> <h1>C++</h1> <p>开发效率：编译慢，文件多，通用库少</p> <p>运行效率：native速度标杆</p> <p>部署便捷性：编写各类的make门槛较高</p> <p>调试便捷性：可通过VisualStudio进行Windows平台调试</p> <p>上手度：2~3年经验的熟手仍然会写出崩溃和泄露代码</p> <p>热更新：可通过DLL进行</p> <p>Web对接：代码啰嗦，第三方库少</p> <p>崩溃处理：Windows下可使用SEH捕获段异常，其他平台只能通过崩溃后进行coredump分析，容错非常差</p> <p>网络库编写难度：基于asio编写较为简单，但总体看来难度不低</p> <p>第三方网络库及框架数量：较多</p> <p>&nbsp;</p> <p>以下是得分</p> <p></td></tr><a href="http://www.cppblog.com/images/cppblog_com/sunicdavy/Windows-Live-Writer/cce8cda86825_E2DC/image_2.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://www.cppblog.com/images/cppblog_com/sunicdavy/Windows-Live-Writer/cce8cda86825_E2DC/image_thumb.png" width="326" height="268"></a> <p>&nbsp; <p>从发文时的项目对这些语言使用率来说，Java，Erlang，C++编写的服务器较多，Golang，JavaScript，C#是第二梯队，Skynet由于上手不是很容易，所以仅有两位数的团队在使用，但总体表现还是比较出色的 <p>对于老团队， C++的服务器工具链和框架已经相对成熟， 完全没必要更换新语言， 只是在对接sdk感觉困难时，可以尝试Golang这些对web有优势的语言进行混合语言开发 <p>对于新团队，开发效率，上手度和部署效率是优先选择的，C#，Golang，JavaScript这些新兴语言会让你事半功倍 <p>对于大规模无需选服的服务器， Skynet的actor模型对扩展会比较容易 <p>对于大公司，好项目，上线后需要通过热更新进行bug修补的，C#，C++，Erlang会是首选 <p>&nbsp; <p>但总的一点， 还是根据团队熟悉度来选择语言，贸然的使用新语言的风险也是很大的 <img src ="http://www.cppblog.com/sunicdavy/aggbug/212611.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2016-01-05 16:51 <a href="http://www.cppblog.com/sunicdavy/archive/2016/01/05/212611.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C/C++服务器架构机制设计总结</title><link>http://www.cppblog.com/sunicdavy/archive/2014/12/18/209225.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Thu, 18 Dec 2014 08:39:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2014/12/18/209225.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/209225.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2014/12/18/209225.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/209225.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/209225.html</trackback:ping><description><![CDATA[<p>近期在写基于go的游戏服务器框架, 在全面脱离C/C++前, 需要对老架构进行一个总结  <p>基于C/C++游戏服务器框架总体设计的还是不错的, 兄弟们总体使用效果都是好评. 因为在技术上喜欢"偷懒", 所以在很多设计上, 都是力求简单, 高效(开发效率).  <p><strong>基于任务的异步DB查询系统, 带多重异步的同步</strong> <p>代码示例:  <div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>&nbsp;</pre><pre><span class="lnum">   2:  </span><span class="kwrd">void</span> BatchQueryPlayerInfo( uint32 ClientID, <span class="kwrd">const</span> std::<span class="kwrd">string</span>&amp; AccountName, int64 CharID )</pre><pre class="alt"><span class="lnum">   3:  </span>{</pre><pre><span class="lnum">   4:  </span>    GDBExecutor-&gt;Commit</pre><pre class="alt"><span class="lnum">   5:  </span>        (    </pre><pre><span class="lnum">   6:  </span>        dynamic_cast&lt;DBDataTask*&gt;( (<span class="kwrd">new</span> DBQueryCharInfo(  ClientID, CharID ) ) </pre><pre class="alt"><span class="lnum">   7:  </span>        -&gt;LinkAtomTask( <span class="kwrd">new</span> DBQueryQuest( ClientID, CharID ) )</pre><pre><span class="lnum">   8:  </span>        -&gt;LinkAtomTask( <span class="kwrd">new</span> DBQuerySkill( ClientID, CharID ) )</pre><pre class="alt"><span class="lnum">   9:  </span>        -&gt;LinkAtomTask( <span class="kwrd">new</span> DBQueryHero( ClientID, CharID ) )</pre><pre><span class="lnum">  10:  </span>        -&gt;LinkAtomTask( <span class="kwrd">new</span> DBQueryAccountInfo( ClientID, AccountName ) )</pre><pre class="alt"><span class="lnum">  11:  </span>        -&gt;LinkAtomTask( <span class="kwrd">new</span> DBQueryEquip( ClientID, CharID ) )</pre><pre><span class="lnum">  12:  </span>        -&gt;LinkAtomTask( <span class="kwrd">new</span> DBQueryObject( ClientID ,CharID ) )</pre><pre class="alt"><span class="lnum">  13:  </span>        -&gt;LinkAtomTask( <span class="kwrd">new</span> DBQueryLevel(ClientID, CharID))</pre><pre><span class="lnum">  14:  </span>        -&gt;LinkAtomTask( <span class="kwrd">new</span> DBQueryChapter(ClientID, CharID))</pre><pre class="alt"><span class="lnum">  15:  </span>        -&gt;LinkAtomTask( <span class="kwrd">new</span> DBQueryActivity( ClientID, CharID ))</pre><pre><span class="lnum">  16:  </span>        )</pre><pre class="alt"><span class="lnum">  17:  </span>        );</pre><pre><span class="lnum">  18:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">  19:  </span>}</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>


<p>这段主要处理玩家在登陆时, 需要从DB查询大量的不同分类的数据. 为了保证效率, 我让每个Task并行执行, 然后通过一个机制, 让所有任务完成后, 回调第一个任务的一个函数. 这样就无需手动实现很多粘合代码, 避免了反复调试和错误</p>
<p><strong>基于protobuf反射机制的语句自动合成</strong></p>
<div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>DBUpdateCharInfo::DBUpdateCharInfo( int64 CharID, <span class="kwrd">const</span> std::<span class="kwrd">string</span>&amp; Buffer )</pre><pre><span class="lnum">   2:  </span>{</pre><pre class="alt"><span class="lnum">   3:  </span>    <span class="kwrd">char</span> buffer[256];</pre><pre><span class="lnum">   4:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   5:  </span>    sprintf( buffer, <span class="str">"update tb_char set $FIELD$ where charid = %lld;"</span>, CharID );</pre><pre><span class="lnum">   6:  </span>        </pre><pre class="alt"><span class="lnum">   7:  </span>    ExecuteCommand( buffer, Buffer, dbopr::FET_Equation );</pre><pre><span class="lnum">   8:  </span>}</pre></div>
<p>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
这段就是一个典型的DB任务, 构造函数提供了CharID和一个由结构体序列化好的buffer, $FIELD$字段, 是通过反射根据Buffer内容, 自动填充字段</p>
<p>这段例子中, $FIELD$可以填充为 hp=100, mp=100之类的. 自动填充避免了因为添加字段的到处添加代码, 还需要调试, 容易搞错</p>
<p>&nbsp;</p>
<p><strong>配置系统概念</strong></p>
<p>基于同一个配置系统, 分层实现不同的需求. 更简单的说, 解决的1个实际问题是: </p>
<p>自己改了配置文件中的ip, 上传svn后, 覆盖了别人的配置, 很多人的解决方法都是, 本地配置不提交. 但同时问题又来了:</p>
<p>当配置中有别人新加的系统配置, 怎么保证每个人都能更新到?</p>
<p>上线后, 服务器交付运维, 他们会对配置有一定程度的修改, 这个时候怎么合并程序配置和运维配置?</p>
<p>其实对于冲突的需求, 只要对系统进行分层就可以解决问题,我的处理方式:</p>
<p>配置分为:</p>
<p>全局配置: 所有服务的总体配置</p>
<p>单服务配置: 本服务的配置, 涉及网络及逻辑</p>
<p>本地配置: 这个配置每个人一份, 不上传SVN</p>
<p>命令行配置: 格式和前面的一致, 这块就可以通过运维进行配置</p>
<p>总体结构其实就是OO的派生概念, 下层可以覆盖, 修改上层的配置</p>
<p>&nbsp;</p>
<p><strong>服务器互联及识别框架</strong></p>
<p>基本功能: 基于一些简单的配置就可以将多台服务器, 同种类的不同服务器互相连接起来, 断线自动重连.</p>
<p>服务器连接后, 所有服务器可知晓并可自动按需连接</p>
<p>逻辑端也很方便的进行广播或者单独发送等</p>
<p>也就是说, 每个服务器的连接和接受端都是带识别名称或id的.</p>
<p>后面觉得这套东西实在是做的复杂, 多整出一台中心服务器来做. 但好歹框架稳定下来了, 也就好了.</p>
<p>&nbsp;</p>
<p><strong>基于lua的服务器web后台框架</strong></p>
<p>思想是很不错的,&nbsp; C++ 配合lua本身绝对是个失败</p>
<p>问题出在web处理,本身都是一个同步阻塞过程, 而这个后台框架是异步方式来做, 所以特别别扭</p>
<p>不过比起以前的本地GM系统, 这块的设计是伟大的进步</p>
<p>&nbsp;</p>
<p>现在正在设计基于golang的服务器框架, 基本框架已经完工, 等待编写逻辑后的实战测试</p>
<p>以上的很多思想在golang的服务器框架都有改进, 特别是golang本身做web也是优秀的, 外加martini这种牛X框架, 更是水到渠成</p>
<p>如果你对服务器框架设计有特别的认识, 或者想碰撞思想, 可以加博客群 309800774或者我的qq: 20998333讨论</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/209225.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2014-12-18 16:39 <a href="http://www.cppblog.com/sunicdavy/archive/2014/12/18/209225.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>lua调试的工具选择</title><link>http://www.cppblog.com/sunicdavy/archive/2014/09/28/208441.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sun, 28 Sep 2014 07:19:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2014/09/28/208441.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/208441.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2014/09/28/208441.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/208441.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/208441.html</trackback:ping><description><![CDATA[<p>最近看到一个关于vs的lua调试插件, 装了vs2012试了下, 忍不住发此文总结下lua各种调试工具</p> <p><strong><a href="http://unknownworlds.com/decoda/">Decoda</a></strong></p> <p>&nbsp;&nbsp;&nbsp; 这是现今地球上调试lua5.1最方便的工具, 没有之一. 强大的注入式调试, 性能极高.支持 挂接进程, 变量展开, 断点等各种日常所需.</p> <p>早期的Decoda是收费工具, 因此质量非常高. </p> <p>&nbsp;&nbsp;&nbsp; Decoda现在已经停止开发并开源了, 调试lua5.2会crash. 源代码可以作为一种技术参考, 很多dll注入修改技术, 灰常牛X</p> <p><a href="http://www.cppblog.com/images/cppblog_com/sunicdavy/Windows-Live-Writer/lua_D2A5/image_7.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://www.cppblog.com/images/cppblog_com/sunicdavy/Windows-Live-Writer/lua_D2A5/image_thumb_2.png" width="623" height="437"></a></p> <p><a href="http://www.luastudio.net/"><strong>LuaStudio</strong></a></p> <p>&nbsp;&nbsp; 比较优秀的调试工具(因为收费), 可以调试lua5.1/5.2, 界面属于vs2008类型, 土豪可以考虑买几套试试</p> <p><img src="http://www.luastudio.net/wp-content/plugins/download-monitor/page-addon/screenshots/4.png" width="621" height="347"></p> <p>&nbsp;</p> <p><a href="http://studio.zerobrane.com/"><strong>ZeroBrane Studio</strong></a></p> <p>对lua5.1支持较好, 5.2也能调但偶尔还是会crash, 基于远程调试方式, 所以性能略低.</p> <p><strong><a href="http://www.keplerproject.org/remdebug/example.html">RemDebug</a></strong></p> <p>没有IDE, 纯命令行方式调试器, 但因为简单, 所以可以参考后写一个自己的程序内建调试器</p> <p><a href="https://babelua.codeplex.com/"><strong>Babe Lua</strong></a></p> <p>把这货放在最后是有原因的, 还记得那句老话: 老外一开源, 我们就有自主研发了, 对的, 这货一定是参考了Decoda的代码后搞出个vs的插件来, 虽然不收费, 但是不提下参考对象的行为还是值得批斗的. 这货在中文博客上说, 不支持挂接到进程(Decoda支持), 不支持64位调试(LuaStudio支持), 调试30~50次偶尔挂1到2次. 哎, 毕竟只是代码搬运工, 不生产代码.</p> <p>这货装上, 能用, 调5.2是不行的, 5.1比Decoda方便点, 毕竟vs支持悬浮显示变量. </p> <p>&nbsp;</p> <p>说了那么多, 其实对于lua5.2版本的调试, 还是没有免费的比较合适的方案, 如果实在想调试, 还是可以参考下RemDebug的原理及lua官方调试文档, 自己通过c api调用写一套适合自己的远程调试工具. 其实没有多复杂, 但总比不调试的好<img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="微笑" src="http://www.cppblog.com/images/cppblog_com/sunicdavy/Windows-Live-Writer/lua_D2A5/wlEmoticon-smile_2.png"></p><img src ="http://www.cppblog.com/sunicdavy/aggbug/208441.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2014-09-28 15:19 <a href="http://www.cppblog.com/sunicdavy/archive/2014/09/28/208441.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>lua module/package 机制的自定义读取</title><link>http://www.cppblog.com/sunicdavy/archive/2014/04/16/206610.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Wed, 16 Apr 2014 12:29:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2014/04/16/206610.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/206610.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2014/04/16/206610.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/206610.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/206610.html</trackback:ping><description><![CDATA[<p>lua5.2后, 官方建议大家放弃module/package机制, 这套机制对于使用者来说是方便的, 对于module的编写者简直要抓狂, 所有module后的函数对_G均不可见, 还要一个个手动在module前转成local调用. 相当反人类. 官方建议大家手动实现package机制. 本博客之前有实现过, 参考<a title="http://www.cppblog.com/sunicdavy/archive/2013/12/10/204696.html" href="http://www.cppblog.com/sunicdavy/archive/2013/12/10/204696.html">http://www.cppblog.com/sunicdavy/archive/2013/12/10/204696.html</a></p> <p>由于要使用protoc-gen-lua, 这东西生成出来的lua依然使用官方的module/package机制. 对于游戏项目来说, 想进行一些自定义读取, 加密等, 就变得不可能. 幸好官方在扩展上支持的还是不错的.</p> <p>参考lua5.2的官方文档<a title="http://www.lua.org/manual/5.2/manual.html#pdf-require" href="http://www.lua.org/manual/5.2/manual.html#pdf-require">http://www.lua.org/manual/5.2/manual.html#pdf-require</a></p> <p>require时, lua会自动根据一定的搜索规律找到加载代码的方法. 这个方法定义在<a name="pdf-package.searchers">package.searchers</a>这个数组中. 一共有4个加载搜索顺序</p> <p>1. preload, 对已加载的module进行直接返回, 对应package.preload[modname]</p> <p>2. lualoader, 对lua文件进行加载, 搜索路径为<a href="http://www.lua.org/manual/5.2/manual.html#pdf-package.path"><code>package.path</code></a></p> <p>3. cloader, 对lua标准dll进行加载, 搜索路径为<a href="http://www.lua.org/manual/5.2/manual.html#pdf-package.cpath"><code>package.cpath</code></a></p> <p>4. croot, 官方文档说的是all-in-one加载器, 感觉很神奇, 感兴趣可以自行参考源码</p> <p>那么, 如果只需要自己的加载器, 只需要这样做:</p> <p><pre class="csharpcode">  package.searchers[2] = function( name )
        print(<span class="str">"try to load"</span>, name )
    end
    package.searchers[3] = nil
    package.searchers[4] = nil
    
    require <span class="str">"libtest"</span></pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>&nbsp;&nbsp;&nbsp; 只保留preload功能, 然后将第二个加载器换成自己的加载函数, 第三,第四直接屏蔽</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/206610.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2014-04-16 20:29 <a href="http://www.cppblog.com/sunicdavy/archive/2014/04/16/206610.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt 4.8.x 升级到Qt5.x的各种坑</title><link>http://www.cppblog.com/sunicdavy/archive/2014/03/01/206000.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sat, 01 Mar 2014 06:25:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2014/03/01/206000.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/206000.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2014/03/01/206000.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/206000.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/206000.html</trackback:ping><description><![CDATA[<p>Qt5 已易主, 脑残的事情也干的越来越多.</p> <p>看qt<a href="http://qt-project.org/downloads">下载页</a>的Qt的windows版本默认提供32位和64位, 那个啥opengl版暂时未理会</p> <p>因为本人系统是win7 64bit, 因此毫无理由的下载了64位的qt5.2版本. 编译了hello world, 结果报错:</p> <p>module machine type 'x64' conflicts with target machine type 'X86' <p>找了半天没查到错误, 后面注意到vs2012的工程编译类型选择的是win32 x86, 才想起是由于qt5的所有lib是64位编译, 而我使用32位的程序去链接, 当然要报错. <p>重新下载32位的qt5.2, 编译正确 <p>&nbsp; <p>另外一个错误也是在前面版本极为少见的: <p>fatal error C1083: Cannot open include file: ’GLES2/gl2.h’: No such file or directory <p>很多人的解决方法是包含QtANGLE下的gles2目录, 但是由于我的工程内的cocos2dx本身也带有这东西. 于是研究了下为啥这版本的qt默认要搞的非要和gles有关系 <p>最终, 发现可以通过定义QT_NO_OPENGL宏来屏蔽opengl的渲染API使用, 编译通过 <p>&nbsp; <p>很是怀念诺基亚时代的qt, 下载,编译一气呵成</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/206000.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2014-03-01 14:25 <a href="http://www.cppblog.com/sunicdavy/archive/2014/03/01/206000.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>自定义TexturePacker插件导出自己的plist文件</title><link>http://www.cppblog.com/sunicdavy/archive/2014/02/06/205645.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Thu, 06 Feb 2014 07:23:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2014/02/06/205645.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/205645.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2014/02/06/205645.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/205645.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/205645.html</trackback:ping><description><![CDATA[<p>cocos2dx引擎使用plist文件, 一种特殊的xml格式作为其atlas纹理的描述文件. plist遵循苹果的xml中key-value的设计风格.对于OC来说是合适的, 但xml本身性能低下, 垃圾内容过多, 也让plist对于高性能游戏引擎不再适合. 因此, 研究TexturePacker的导出插件技术</p> <p>TexturePacker的自定义插件目录位于其安装目录的bin\exporters\下, 但有一些插件属于内建支持, 例如cocos2dx的plist格式, 因此无法找到对应插件</p> <p>本人参考shiva3d插件, 对应导出界面的DataFormat中的Shiva3D, 快速学会了如何导出</p> <p>官方文档位于<a title="http://www.codeandweb.com/texturepacker/documentation/#customization" href="http://www.codeandweb.com/texturepacker/documentation/#customization">http://www.codeandweb.com/texturepacker/documentation/#customization</a></p> <p>插件的基本格式及原理是:</p> <p>bin\exporters\下的某一目录下存在的一个名为exporter.xml文件作为插件的描述,例如:</p> <div class="csharpcode"><pre class="alt"><span class="kwrd">&lt;</span><span class="html">exporter</span> <span class="attr">version</span><span class="kwrd">="1.0"</span><span class="kwrd">&gt;</span></pre><pre>    <span class="rem">&lt;!-- identifier of the exporter --&gt;</span></pre><pre class="alt">    <span class="kwrd">&lt;</span><span class="html">name</span><span class="kwrd">&gt;</span>shiva3d<span class="kwrd">&lt;/</span><span class="html">name</span><span class="kwrd">&gt;</span></pre><pre>&nbsp;</pre><pre class="alt">    <span class="rem">&lt;!-- display name of the exporter for the combo box --&gt;</span></pre><pre>    <span class="kwrd">&lt;</span><span class="html">displayName</span><span class="kwrd">&gt;</span>Shiva3D<span class="kwrd">&lt;/</span><span class="html">displayName</span><span class="kwrd">&gt;</span></pre><pre class="alt">    </pre><pre>    <span class="rem">&lt;!-- description of the exporter --&gt;</span></pre><pre class="alt">    <span class="kwrd">&lt;</span><span class="html">description</span><span class="kwrd">&gt;</span>Exporter for Shiva3D.<span class="kwrd">&lt;/</span><span class="html">description</span><span class="kwrd">&gt;</span></pre><pre>&nbsp;</pre><pre class="alt">    <span class="rem">&lt;!-- exporter version --&gt;</span></pre><pre>    <span class="kwrd">&lt;</span><span class="html">version</span><span class="kwrd">&gt;</span>1.0<span class="kwrd">&lt;/</span><span class="html">version</span><span class="kwrd">&gt;</span></pre><pre class="alt">    </pre><pre>    <span class="rem">&lt;!-- currently only one file allowed - more to come with update --&gt;</span></pre><pre class="alt">    <span class="kwrd">&lt;</span><span class="html">files</span><span class="kwrd">&gt;</span></pre><pre>        <span class="kwrd">&lt;</span><span class="html">file</span><span class="kwrd">&gt;</span></pre><pre class="alt">            <span class="rem">&lt;!-- name of this file variable --&gt;</span></pre><pre>            <span class="kwrd">&lt;</span><span class="html">name</span><span class="kwrd">&gt;</span>xml<span class="kwrd">&lt;/</span><span class="html">name</span><span class="kwrd">&gt;</span></pre><pre class="alt">&nbsp;</pre><pre>            <span class="rem">&lt;!-- human readable name (for GUI) --&gt;</span></pre><pre class="alt">            <span class="kwrd">&lt;</span><span class="html">displayName</span><span class="kwrd">&gt;</span>XML<span class="kwrd">&lt;/</span><span class="html">displayName</span><span class="kwrd">&gt;</span></pre><pre>&nbsp;</pre><pre class="alt">            <span class="rem">&lt;!-- file extension for the file --&gt;</span></pre><pre>            <span class="kwrd">&lt;</span><span class="html">fileExtension</span><span class="kwrd">&gt;</span>xml<span class="kwrd">&lt;/</span><span class="html">fileExtension</span><span class="kwrd">&gt;</span></pre><pre class="alt">&nbsp;</pre><pre>            <span class="rem">&lt;!-- name of the template file --&gt;</span></pre><pre class="alt">            <span class="kwrd">&lt;</span><span class="html">template</span><span class="kwrd">&gt;</span>shiva.xml<span class="kwrd">&lt;/</span><span class="html">template</span><span class="kwrd">&gt;</span></pre><pre>        <span class="kwrd">&lt;/</span><span class="html">file</span><span class="kwrd">&gt;</span></pre><pre class="alt">    <span class="kwrd">&lt;/</span><span class="html">files</span><span class="kwrd">&gt;</span></pre><pre>&nbsp;</pre><pre class="alt">    <span class="rem">&lt;!-- target framework supports trimming --&gt;</span></pre><pre>    <span class="kwrd">&lt;</span><span class="html">supportsTrimming</span><span class="kwrd">&gt;</span>false<span class="kwrd">&lt;/</span><span class="html">supportsTrimming</span><span class="kwrd">&gt;</span></pre><pre class="alt">&nbsp;</pre><pre>    <span class="rem">&lt;!-- target framework supports rotated sprites --&gt;</span></pre><pre class="alt">    <span class="kwrd">&lt;</span><span class="html">supportsRotation</span><span class="kwrd">&gt;</span>true<span class="kwrd">&lt;/</span><span class="html">supportsRotation</span><span class="kwrd">&gt;</span></pre><pre>&nbsp;</pre><pre class="alt">    <span class="rem">&lt;!-- rotated sprites direction (cw/ccw) --&gt;</span></pre><pre>    <span class="kwrd">&lt;</span><span class="html">rotationDirection</span><span class="kwrd">&gt;</span>cw<span class="kwrd">&lt;/</span><span class="html">rotationDirection</span><span class="kwrd">&gt;</span></pre><pre class="alt">&nbsp;</pre><pre>    <span class="rem">&lt;!-- supports npot sizes --&gt;</span></pre><pre class="alt">    <span class="kwrd">&lt;</span><span class="html">supportsNPOT</span><span class="kwrd">&gt;</span>true<span class="kwrd">&lt;/</span><span class="html">supportsNPOT</span><span class="kwrd">&gt;</span></pre><pre>&nbsp;</pre><pre class="alt">    <span class="rem">&lt;!-- supports file name stripping (remove .png etc) --&gt;</span></pre><pre>    <span class="kwrd">&lt;</span><span class="html">supportsTrimSpriteNames</span><span class="kwrd">&gt;</span>yes<span class="kwrd">&lt;/</span><span class="html">supportsTrimSpriteNames</span><span class="kwrd">&gt;</span></pre><pre class="alt">&nbsp;</pre><pre>    <span class="rem">&lt;!-- supports texure subpath --&gt;</span></pre><pre class="alt">    <span class="kwrd">&lt;</span><span class="html">supportsTextureSubPath</span><span class="kwrd">&gt;</span>yes<span class="kwrd">&lt;/</span><span class="html">supportsTextureSubPath</span><span class="kwrd">&gt;</span></pre><pre>&nbsp;</pre><pre class="alt"><span class="kwrd">&lt;/</span><span class="html">exporter</span><span class="kwrd">&gt;</span></pre><pre>&nbsp;</pre><pre class="alt">&nbsp;</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>&nbsp;</p>
<p>在Template字段中, 描述同目录的导出文件格式模板. TexturePacker使用一种叫<a href="http://www.codeandweb.com/outbound/www-grantlee-org-apidox-for_themers-html/">Grantlee</a>的模板引擎,类似于Python使用的Django模板引擎, 文档参见:<a href="http://www.codeandweb.com/outbound/www-grantlee-org-apidox-for_themers-html/">Grantlee Documentation</a>. 简单的文本格式可以参考shiva.xml快速学会</p>
<p>这里我们使用protobuf的文本格式(极为类似json)导出plist, 下面是导出模板</p>
<p>&nbsp;</p>
<div class="csharpcode"><pre class="alt">{% for sprite in allSprites %}</pre><pre>Sprite {</pre><pre class="alt">    Name: "{{sprite.trimmedName}}"</pre><pre>    FrameX: {{sprite.frameRect.x}}</pre><pre class="alt">    FrameY: {{sprite.frameRect.y}}</pre><pre>    FrameWidth: {{sprite.frameRectWithoutRotation.width}}</pre><pre class="alt">    FrameHeight: {{sprite.frameRectWithoutRotation.height}}</pre><pre>    OffsetX: {{sprite.cornerOffset.x}}</pre><pre class="alt">    OffsetY: {{sprite.cornerOffset.y}}</pre><pre>    OriginalWidth: {{sprite.untrimmedSize.width}}</pre><pre class="alt">    OriginalHeight: {{sprite.untrimmedSize.height}}</pre><pre>    {% if sprite.rotated %}Rotated: true {% endif %}</pre><pre class="alt">}</pre><pre>{% endfor %}</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>导出的结果类似于:</p>
<div class="csharpcode"><pre class="alt">&nbsp;</pre><pre>Sprite {</pre><pre class="alt">    Name: <span class="str">"car01"</span></pre><pre>    FrameX: 100</pre><pre class="alt">    FrameY: 129</pre><pre>    FrameWidth: 76</pre><pre class="alt">    FrameHeight: 47</pre><pre>    OffsetX: 0</pre><pre class="alt">    OffsetY: 0</pre><pre>    OriginalWidth: 76</pre><pre class="alt">    OriginalHeight: 47</pre><pre>    Rotated: <span class="kwrd">true</span> </pre><pre class="alt">}</pre><pre>&nbsp;</pre><pre class="alt">Sprite {</pre><pre>    Name: <span class="str">"car02"</span></pre><pre class="alt">    FrameX: 100</pre><pre>    FrameY: 51</pre><pre class="alt">    FrameWidth: 76</pre><pre>    FrameHeight: 47</pre><pre class="alt">    OffsetX: 0</pre><pre>    OffsetY: 0</pre><pre class="alt">    OriginalWidth: 76</pre><pre>    OriginalHeight: 47</pre><pre class="alt">    Rotated: <span class="kwrd">true</span> </pre><pre>}</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>


<p>...</p>
<p>导出插件还支持js扩展, 具体内容请继续参考官方文档, 但对于简单的文本格式, 这种方式已经足够了</p>
<p>对比plist后, 发现plist中的垃圾信息极为多, 而且作为spriteframe的name居然带有扩展名...&nbsp; 因此脱离plist,编写自己的导出插件才是王道!</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/205645.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2014-02-06 15:23 <a href="http://www.cppblog.com/sunicdavy/archive/2014/02/06/205645.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt技术优势</title><link>http://www.cppblog.com/sunicdavy/archive/2014/01/14/205359.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Tue, 14 Jan 2014 03:53:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2014/01/14/205359.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/205359.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2014/01/14/205359.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/205359.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/205359.html</trackback:ping><description><![CDATA[<p>1. Qt这个C++的图形库由Trolltech在1994年左右开发。它可以运行在Windows,Mac OS X, Unix，还有像Sharp Zaurus这类嵌入式系统中。Qt是完全面向对象的。 <p>2. Qt的架构明显是经过精心设计的面向对象的。Qt因此在命名，继承，类的组织等方面保持了优秀的一致性。你只需要提供唯一一个方法的参数，仅此一个。在不同的类中调用方式也是有很强的连贯性。返回值也很有逻辑性。所有一切达到了简单和强大的和谐统一。一旦你使用了其中一个类，其他的类也就触类旁通，因为他们是一致的。 <p>3. Qt不强制使用任何设计模式。如果你认为恰当，使用Document/view没有任何问题。不使用也没有任何问题。 <p>4. MFC是事件驱动的架构。要执行任何操作，都必须是对特定的消息作出响应。Windows对应用程序发送的信息数以千计，遗憾的是，要分清楚这些分繁芜杂的消息是很困难的，并且关于这方面的文档并不能很好的解决这些问题。<br>Qt的消息机制是建立在SIGNAL()发送和SLOT()接受的基础上的。这个机制是对象间建立联系的核心机制。利用SIGNAL()可以传递任何的参数。他的功能非常的强大。可以直接大传递信号给SLOT()，因此可以清楚的理解要发生的事情。一个类所发送的信号的数量通常非常的小(4或者5)，并且文档也非常的齐全。这让你感觉到一切尽在掌握之中。SIGNAL/SLOT机制类似于Java中listener机制,不过这种机制更加轻量级，功能更齐全。 <p>5. Qt拥有非常简单而又不失强大的layout机制，布局灵活多变<br>Qt还提供了一个图形用户工具，Qt Designer，可以用来帮助建立用户界面。可以修改所使用的任何控件的属性。不用将他们放在严格的位置，可以通过layout完美的组织他们。这个工具所产生的代码我们是可以实际上阅读并且可以理解的。生成的代码单独放在一个文件里，在编程的同时，你可以随心所欲的多次重新生成用户界面。<br>Qt Designer可以让你完成许多在MFC中不可能完成的任务，比如用预先填好的生成listview，在每个tab上用不同的view来使用tab 控制。 <p>6. 使用MFC，一部分开发过程要依靠“resources”,在很多的案例中开发者必须使用他们。这样会导致如下的后果：出了Visual Studio，你很难使用其他的工具来完成开发。<br>资源编辑器仅有有限的功能，比如：通过Dialog编辑器不可能改变所有的属性，一些属性可以改变，另一些属性则不可能改变。(译者注：下面还有两条陈述MFC缺点的实例，但我感觉这些已经够说明问题了，暂时删节不译)<br>然而Qt并没有资源的概念，这就解决了以上所提到的问题。Qt提供了一个脚本使得能将编入你的代码。对于界面设计，Qt Designer则创建了可读的代码。 <p>7. Qt的文档完备且详细的覆盖了Qt的方方面面，竟然仅有18M。每一个类和方法都被详尽描述，巨细靡遗，举例充实。通过Trolltech公司提供的链接或者是Qt Assistant工具，可以方便的从一个类或者方法跳转到其他的类。文档还包含了一个初学者教程和一些典型应用的例子 <p>8. 在发布基于MFC的软件时，必须依靠存在于客户电脑上的MFC。但是这是不安全的，同样是MFC42.dll，可以基于相同的库得到3个不同的版本。通常，需要检查是否拥有正确的MFC42.dll版本，如果不是，就升级它。但是升级MFC42.dll会改变很多软件的行为。<br>Qt则没有这个风险，因为Qt压根就没有“升级整个系统”这个概念。 <p>9. Qt 完全支持CSS2，这使得Qt应用程序，无论是美化还是换肤，实现起来都相当简单 <p>10. Qt自带翻译器，可以随意切换软件语言 <p>&nbsp; <p>在使用Qt动态链接库的情况下，根据LGPL协议规定，是可以闭源发布任何形式的程序的。 <p>参考链接： <p>来自Qt官方论坛的讨论：<a href="http://qt-project.org/forums/viewthread/2428">http://qt-project.org/forums/viewthread/2428</a> <p>博客链接：<a href="http://devbean.blog.51cto.com/448512/313477">http://devbean.blog.51cto.com/448512/313477</a> <p>&nbsp; <p>&nbsp; <p>转自:<a href="http://blog.csdn.net/superzhaifd/article/details/18224923">http://blog.csdn.net/superzhaifd/article/details/18224923</a>&nbsp;<a href="http://blog.csdn.net/superzhaifd">翟冬狼_Trump</a> <p>&nbsp; <p>本人较喜欢第二点: 不使用任何设计模式构建底层. 设计模式只是思想, 也是羁绊. 大量使用只会让系统臃肿.</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/205359.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2014-01-14 11:53 <a href="http://www.cppblog.com/sunicdavy/archive/2014/01/14/205359.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>protobuf编译中遇到的c compiler cannot create executables错误解决方法</title><link>http://www.cppblog.com/sunicdavy/archive/2014/01/12/205330.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sun, 12 Jan 2014 10:12:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2014/01/12/205330.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/205330.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2014/01/12/205330.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/205330.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/205330.html</trackback:ping><description><![CDATA[<p>最近下载了最新的linux mint 16和ubuntu 12中分别尝试编译protobuf 2.5.0.但都是报c compiler cannot create executables的错. 查过网上解决方案, 清一色都是export LIBS=之类的, 无法解决问题. 最终一个回帖启发了我, 使用apt-get install g++ 发现C++编译器根本都没安… 安装完毕, 一切搞定. linux mint越来越娱乐了, 连g++都不默认装了…</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/205330.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2014-01-12 18:12 <a href="http://www.cppblog.com/sunicdavy/archive/2014/01/12/205330.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>超越luabind的luaBridge</title><link>http://www.cppblog.com/sunicdavy/archive/2013/12/07/204648.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sat, 07 Dec 2013 06:05:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2013/12/07/204648.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/204648.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2013/12/07/204648.html#Feedback</comments><slash:comments>24</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/204648.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/204648.html</trackback:ping><description><![CDATA[<p>&nbsp;</p> <p>最近准备在手机项目客户端中使用lua, 以前一直在服务器使用luabind. 另外, tolua++也体验过, LuaPlus也在早年用过. 以下是本人对这些绑定库的个人感觉:</p> <p>luabind</p> <p>利用boost机制把绑定做到极致, 比较适合主c++, 弱lua的脚本框架. </p> <p>作者已经停止更新, 在windows/linux编译没问题, 但是在ios的LLVM下, 无法编译</p> <p>tolua++</p> <p>像cocos2dx使用tolua++也是可以理解的, 那么多函数需要绑定, tolua++的头文件parse及自动代码生成节约了很多手动绑定的时间.</p> <p>但是看到代码中有一部分bugfix就心存不安(纯个人感觉, 本人使用不多, 欢迎砖头伺候),另外, tolua++只能由脚本层驱动C++, 而没有将已经实例化的句柄注册到lua的功能也是煞笔啊</p> <p>&nbsp;</p> <p>LuaPlus</p> <p>接口较为简单, 适于初学者上手, 无任何的模板, 性能不高</p> <p>&nbsp;</p> <p>luaBridge</p> <p>项目地址: <a href="https://github.com/vinniefalco/LuaBridge">https://github.com/vinniefalco/LuaBridge</a></p> <p>手册: <a href="http://vinniefalco.com/LuaBridge/Manual.html">http://vinniefalco.com/LuaBridge/Manual.html</a></p> <p>纯头文件实现, 无需编译, 包含进入工程即可, 接口简洁高效</p> <p>相比luabind, 唯一不能实现的常用功能就是枚举, 但是可以支持类成员静态变量注册, 这个就无所谓了, 手写一个枚举支持也很简单</p> <p>看下演示代码:</p><pre class="csharpcode">
<span class="kwrd">class</span> A
{
<span class="kwrd">public</span>:
    A( )
    {

    }
    <span class="kwrd">virtual</span> <span class="kwrd">void</span> foo( <span class="kwrd">int</span> a )
    {
        printf(<span class="str">"foo base\n"</span>);
    }

    std::<span class="kwrd">string</span> Member;
};

<span class="kwrd">class</span> B : <span class="kwrd">public</span> A
{
<span class="kwrd">public</span>:
    <span class="kwrd">virtual</span> <span class="kwrd">void</span> foo( <span class="kwrd">int</span> a )
    {
        printf(<span class="str">"foo inherited\n"</span>);
    }
};
</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<pre class="csharpcode">
<span class="kwrd">void</span> foo( <span class="kwrd">int</span> b )
{

}
</pre>
<p>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</p><pre class="csharpcode">luabridge::getGlobalNamespace(L)
        .beginClass&lt;A&gt;(<span class="str">"Sobj"</span>)
            .addConstructor&lt;<span class="kwrd">void</span> (*) (<span class="kwrd">void</span>)&gt; ()
            .addFunction(<span class="str">"foo"</span>, &amp;A::foo)
            .addData(<span class="str">"Member"</span>,&amp;A::Member)
        .endClass()
        .deriveClass&lt;B, A&gt;(<span class="str">"SSec"</span>)
            .addFunction(<span class="str">"foo"</span>,&amp;B::foo )
        .endClass();

    luabridge::getGlobalNamespace(L).addFunction(<span class="str">"foo"</span>, foo );


    B ins;
    ins.Member = <span class="str">"data"</span>;
    luabridge::setGlobal(L, ins, <span class="str">"ins"</span>);</pre>
<p>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</p><pre class="csharpcode">lua侧的代码

local a = Sobj()
a:foo(2)
a.Member = <span class="str">"hello"</span>


ins:foo(3)
</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style><img src ="http://www.cppblog.com/sunicdavy/aggbug/204648.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2013-12-07 14:05 <a href="http://www.cppblog.com/sunicdavy/archive/2013/12/07/204648.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>luabind 0.9.1在boost 1.49+和gcc-4.6.3以上版本的编译问题处理</title><link>http://www.cppblog.com/sunicdavy/archive/2013/09/24/203409.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Tue, 24 Sep 2013 08:46:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2013/09/24/203409.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/203409.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2013/09/24/203409.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/203409.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/203409.html</trackback:ping><description><![CDATA[<p>将boost更新到1.53时, 发现luabind死活编译不过, 报错如下</p> <p>error: missing binary operator before token "("</p> <p>根据老外的描述, boost中的BOOST_PP_ITERATION_FLAGS从1.49版本后发生了一些变化.</p> <p>在git找到一个patch, 链接<a href="https://gist.github.com/ObKo/2011636">在此</a></p> <p>以下简单描述</p> <p>修改call_function.hpp, call_member.hpp及wrapper_base.hpp</p> <p>去掉#elif BOOST_PP_ITERATION_FLAGS() == 1</p> <p>更换为</p> <p>#else</p> <p>#if BOOST_PP_ITERATION_FLAGS() == 1</p><pre><p>然后在源码底部加一个#endif即可</p></pre><img src ="http://www.cppblog.com/sunicdavy/aggbug/203409.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2013-09-24 16:46 <a href="http://www.cppblog.com/sunicdavy/archive/2013/09/24/203409.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt应用程序使用图形解码无法显示的问题</title><link>http://www.cppblog.com/sunicdavy/archive/2013/08/10/202448.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sat, 10 Aug 2013 01:44:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2013/08/10/202448.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/202448.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2013/08/10/202448.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/202448.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/202448.html</trackback:ping><description><![CDATA[<p>最近发现一个Qt写的切图软件, 导入PNG图片可以显示, 而JPEG图片无法显示. 开发机正常. Google了一下, 发现Qt通过外部插件机制支持各种扩展功能. </p> <p>在启动前, 添加如下代码:</p> <p>QApplication qapp(argc, argv);&nbsp;&nbsp;&nbsp; </p> <p>qapp.addLibraryPath(QCoreApplication::applicationDirPath()+"/plugins");<br></p> <p>将QT开发目录下: Qt\4.8.2\plugins\拷贝到Qt的exe目录即可</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/202448.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2013-08-10 09:44 <a href="http://www.cppblog.com/sunicdavy/archive/2013/08/10/202448.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Cygwin环境下使用Android NDK r8e编译boost 1.53</title><link>http://www.cppblog.com/sunicdavy/archive/2013/07/20/201993.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sat, 20 Jul 2013 08:23:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2013/07/20/201993.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/201993.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2013/07/20/201993.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/201993.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/201993.html</trackback:ping><description><![CDATA[<p>这里不能不说Google确实搜了1天都没解决问题, baidu第一个就解决了... <p>cygwin参考这里 <p><a href="http://my.oschina.net/tonywolf/blog/49214">http://my.oschina.net/tonywolf/blog/49214</a> <p>简单的说 <p>1.下载cygwin的网络安装包(第一次安装只能这样) <p>2. 选择靠前一点的网站进行下载( 下好的包可以留着, 下次安装直接从文件夹中选择就可以安装) <p>cygwin下使用NDK编译boost参考这里 <p><a href="http://blog.sina.com.cn/s/blog_a6946c8a01016aot.html">http://blog.sina.com.cn/s/blog_a6946c8a01016aot.html</a> <p>细节注意: <p>1. boost官网下载boost_1_53_0.tar.bz2, 解压放在android-ndk-r8e/sources下 <p>2. 生成boost编译工具: 在boost目录下运行 ./bootstrap.sh 或者 bootstrap.bat 生成 b2 <p>3. 修改 boost/tools/build/v2/user-config.jam 内容修改如下 <div class="csharpcode"><pre class="alt">import os ;</pre><pre>&nbsp;</pre><pre class="alt"><span class="kwrd">if</span> [ os.name ] = CYGWIN || [ os.name ] = NT {</pre><pre>androidPlatform = windows ;</pre><pre class="alt">}</pre><pre><span class="kwrd">else</span> <span class="kwrd">if</span> [ os.name ] = LINUX {</pre><pre class="alt">androidPlatform = linux-x86_64 ;</pre><pre>}</pre><pre class="alt"><span class="kwrd">else</span> <span class="kwrd">if</span> [ os.name ] = MACOSX {</pre><pre>androidPlatform = darwin-x86 ;</pre><pre class="alt">}</pre><pre>&nbsp;</pre><pre class="alt">modules.poke : NO_BZIP2 : 1 ;</pre><pre>ANDROID_NDK = ../.. ;</pre><pre class="alt">using gcc : android4.6 : $(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-g++ :</pre><pre>&lt;archiver&gt;$(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ar</pre><pre class="alt">&lt;ranlib&gt;$(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ranlib</pre><pre>&lt;compileflags&gt;--sysroot=$(ANDROID_NDK)/platforms/android-9/arch-arm</pre><pre class="alt">&lt;compileflags&gt;-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.6/include</pre><pre>&lt;compileflags&gt;-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include</pre><pre class="alt">&lt;compileflags&gt;-DNDEBUG</pre><pre>&lt;compileflags&gt;-D__GLIBC__</pre><pre class="alt">&lt;compileflags&gt;-DBOOST_FILESYSTEM_VERSION=3</pre><pre>&lt;compileflags&gt;-lstdc++</pre><pre class="alt">&lt;compileflags&gt;-lgnustl_shared</pre><pre>&lt;compileflags&gt;-mthumb</pre><pre class="alt">&lt;compileflags&gt;-fno-strict-aliasing</pre><pre>&lt;compileflags&gt;-std=gnu++11</pre><pre class="alt">&lt;compileflags&gt;-O2</pre><pre>;</pre><pre class="alt">&nbsp;</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>


<p>4. 为了安全起见, 我打了个BoostForAndriod上的补丁: 手动修改下就好了
<p>&nbsp; <div class="csharpcode"><pre class="alt">diff -ruN boost_1_53_0-boot/boost/asio/detail/socket_types.hpp boost_1_53_0-patched/boost/asio/detail/socket_types.hpp</pre><pre>--- boost_1_53_0-boot/boost/asio/detail/socket_types.hpp     2012-01-15 14:46:25.000000000 +0100</pre><pre class="alt">+++ boost_1_53_0-patched/boost/asio/detail/socket_types.hpp     2012-06-27 19:19:01.279562338 +0200</pre><pre>@@ -123,7 +123,12 @@</pre><pre class="alt">typedef int socket_type;</pre><pre>const int invalid_socket = -1;</pre><pre class="alt">const int socket_error_retval = -1;</pre><pre>+// @Moss - Some platforms do not define it (Android)</pre><pre class="alt">+<span class="rem">#if defined(INET_ADDRSTRLEN)</span></pre><pre>const int max_addr_v4_str_len = INET_ADDRSTRLEN;</pre><pre class="alt">+<span class="rem">#else // defined(INET_ADDRSTRLEN)</span></pre><pre>+const int max_addr_v4_str_len = 16;</pre><pre class="alt">+<span class="rem">#endif // defined(INET_ADDRSTRLEN)</span></pre><pre><span class="rem">#if defined(INET6_ADDRSTRLEN)</span></pre><pre class="alt">const int max_addr_v6_str_len = INET6_ADDRSTRLEN + 1 + IF_NAMESIZE;</pre><pre><span class="rem">#else // defined(INET6_ADDRSTRLEN)</span></pre><pre class="alt">diff -ruN boost_1_53_0-boot/boost/asio/ip/impl/address_v6.ipp boost_1_53_0-patched/boost/asio/ip/impl/address_v6.ipp</pre><pre>--- boost_1_53_0-boot/boost/asio/ip/impl/address_v6.ipp     2012-01-15 14:46:25.000000000 +0100</pre><pre class="alt">+++ boost_1_53_0-patched/boost/asio/ip/impl/address_v6.ipp     2012-06-27 19:19:11.029581297 +0200</pre><pre>@@ -11,6 +11,23 @@</pre><pre class="alt"><span class="rem">#ifndef BOOST_ASIO_IP_IMPL_ADDRESS_V6_IPP</span></pre><pre><span class="rem">#define BOOST_ASIO_IP_IMPL_ADDRESS_V6_IPP</span></pre><pre class="alt">&nbsp;</pre><pre>+// @Moss - Define IPv6 macros</pre><pre class="alt">+<span class="rem">#if !defined(IN6_IS_ADDR_MULTICAST) </span></pre><pre>+<span class="rem">#define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)</span></pre><pre class="alt">+<span class="rem">#endif</span></pre><pre>+</pre><pre class="alt">+<span class="rem">#if !defined(IN6_IS_ADDR_MC_NODELOCAL)</span></pre><pre>+<span class="rem">#define IN6_IS_ADDR_MC_NODELOCAL(a) \</span></pre><pre class="alt">+        (IN6_IS_ADDR_MULTICAST(a) \</pre><pre>+         &amp;&amp; ((((__const uint8_t *) (a))[1] &amp; 0xf) == 0x1))</pre><pre class="alt">+<span class="rem">#endif</span></pre><pre>+</pre><pre class="alt">+<span class="rem">#if !defined(IN6_IS_ADDR_MC_GLOBAL)</span></pre><pre>+<span class="rem">#define IN6_IS_ADDR_MC_GLOBAL(a) \</span></pre><pre class="alt">+        (IN6_IS_ADDR_MULTICAST(a) \</pre><pre>+         &amp;&amp; ((((__const uint8_t *) (a))[1] &amp; 0xf) == 0xe))</pre><pre class="alt">+<span class="rem">#endif</span></pre><pre>+</pre><pre class="alt"><span class="rem">#if defined(_MSC_VER) &amp;&amp; (_MSC_VER &gt;= 1200)</span></pre><pre><span class="rem"># pragma once</span></pre><pre class="alt"><span class="rem">#endif // defined(_MSC_VER) &amp;&amp; (_MSC_VER &gt;= 1200)</span></pre><pre>diff -ruN boost_1_53_0-boot/boost/config/user.hpp boost_1_53_0-patched/boost/config/user.hpp</pre><pre class="alt">--- boost_1_53_0-boot/boost/config/user.hpp     2004-01-10 13:10:00.000000000 +0100</pre><pre>+++ boost_1_53_0-patched/boost/config/user.hpp     2012-06-27 19:18:46.129532736 +0200</pre><pre class="alt">@@ -13,6 +13,15 @@</pre><pre>//  configuration policy:</pre><pre class="alt">//</pre><pre>&nbsp;</pre><pre class="alt">+// Android defines</pre><pre>+<span class="rem">#define __arm__ 1</span></pre><pre class="alt">+<span class="rem">#define _REENTRANT 1</span></pre><pre>+<span class="rem">#define _GLIBCXX__PTHREADS 1</span></pre><pre class="alt">+// There is problem with std::atomic on android (and some other platforms).</pre><pre>+// See this link <span class="kwrd">for</span> more info:</pre><pre class="alt">+// https://code.google.com/p/android/issues/detail?id=42735<span class="rem">#makechanges</span></pre><pre>+<span class="rem">#define BOOST_ASIO_DISABLE_STD_ATOMIC 1</span></pre><pre class="alt">+</pre><pre>// define this to locate a compiler config file:</pre><pre class="alt">// <span class="rem">#define BOOST_COMPILER_CONFIG &lt;myheader&gt;</span></pre><pre>&nbsp;</pre><pre class="alt">diff -ruN boost_1_53_0-boot/boost/detail/endian.hpp boost_1_53_0-patched/boost/detail/endian.hpp</pre><pre>--- boost_1_53_0-boot/boost/detail/endian.hpp     2011-03-29 23:58:48.000000000 +0200</pre><pre class="alt">+++ boost_1_53_0-patched/boost/detail/endian.hpp     2012-06-27 19:18:39.359519453 +0200</pre><pre>@@ -31,7 +31,7 @@</pre><pre class="alt">// GNU libc offers the helpful header &lt;endian.h&gt; which defines</pre><pre>// __BYTE_ORDER</pre><pre class="alt">&nbsp;</pre><pre>-<span class="rem">#if defined (__GLIBC__)</span></pre><pre class="alt">+<span class="rem">#if defined (__GLIBC__) || defined(ANDROID)</span></pre><pre><span class="rem"># include &lt;endian.h&gt;</span></pre><pre class="alt"><span class="rem"># if (__BYTE_ORDER == __LITTLE_ENDIAN)</span></pre><pre><span class="rem">#  define BOOST_LITTLE_ENDIAN</span></pre><pre class="alt">diff -ruN boost_1_53_0-boot/boost/interprocess/detail/workaround.hpp boost_1_53_0-patched/boost/interprocess/detail/workaround.hpp</pre><pre>--- boost_1_53_0-boot/boost/interprocess/detail/workaround.hpp     2011-12-26 18:21:36.000000000 +0100</pre><pre class="alt">+++ boost_1_53_0-patched/boost/interprocess/detail/workaround.hpp     2012-06-27 19:18:52.909546004 +0200</pre><pre>@@ -54,7 +54,7 @@</pre><pre class="alt">    <span class="rem">#endif</span></pre><pre>&nbsp;</pre><pre class="alt">    //Check <span class="kwrd">for</span> XSI shared memory objects. They are available <span class="kwrd">in</span> nearly all UNIX platforms</pre><pre>-   <span class="rem">#if !defined(__QNXNTO__)</span></pre><pre class="alt">+   <span class="rem">#if !defined(__QNXNTO__) &amp;&amp; !defined(ANDROID)</span></pre><pre>       <span class="rem">#define BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS</span></pre><pre class="alt">    <span class="rem">#endif</span></pre><pre>&nbsp;</pre><pre class="alt">diff -ruN boost_1_53_0-boot/libs/filesystem/src/operations.cpp boost_1_53_0-patched/libs/filesystem/src/operations.cpp</pre><pre>--- boost_1_53_0-boot/libs/filesystem/src/operations.cpp     2012-01-28 15:40:16.000000000 +0100</pre><pre class="alt">+++ boost_1_53_0-patched/libs/filesystem/src/operations.cpp     2012-06-27 19:19:19.269597266 +0200</pre><pre>@@ -73,13 +73,15 @@</pre><pre class="alt">     const fs::path dot_dot_path(<span class="str">".."</span>);</pre><pre><span class="rem">#   include &lt;sys/types.h&gt;</span></pre><pre class="alt"><span class="rem">#   include &lt;sys/stat.h&gt;</span></pre><pre>-<span class="rem">#   if !defined(__APPLE__) &amp;&amp; !defined(__OpenBSD__)</span></pre><pre class="alt">+<span class="rem">#   if !defined(__APPLE__) &amp;&amp; !defined(__OpenBSD__) &amp;&amp; !defined(__ANDROID__) &amp;&amp; !defined(ANDROID)</span></pre><pre><span class="rem">#     include &lt;sys/statvfs.h&gt;</span></pre><pre class="alt"><span class="rem">#     define BOOST_STATVFS statvfs</span></pre><pre><span class="rem">#     define BOOST_STATVFS_F_FRSIZE vfs.f_frsize</span></pre><pre class="alt"><span class="rem">#   else</span></pre><pre><span class="rem">#     ifdef __OpenBSD__</span></pre><pre class="alt"><span class="rem">#     include &lt;sys/param.h&gt;</span></pre><pre>+<span class="rem">#     elif defined(__ANDROID__) || defined(ANDROID) // @Moss - Android messes up a bit with some headers, this one is the correct one :D</span></pre><pre class="alt">+<span class="rem">#     include &lt;sys/vfs.h&gt;</span></pre><pre><span class="rem">#     endif</span></pre><pre class="alt"><span class="rem">#     include &lt;sys/mount.h&gt;</span></pre><pre><span class="rem">#     define BOOST_STATVFS statfs</span></pre><pre class="alt">@@ -206,7 +208,19 @@</pre><pre>          || ::mkdir(to.c_str(),from_stat.st_mode)!= 0))</pre><pre class="alt"><span class="rem">#   define BOOST_COPY_FILE(F,T,FailIfExistsBool)copy_file_api(F, T, FailIfExistsBool)</span></pre><pre><span class="rem">#   define BOOST_MOVE_FILE(OLD,NEW)(::rename(OLD, NEW)== 0)</span></pre><pre class="alt">+<span class="rem">#if defined(__ANDROID__) || defined(ANDROID)</span></pre><pre>+    int BOOST_RESIZE_FILE(const char *path, off_t size)</pre><pre class="alt">+    {</pre><pre>+      int result = -1;</pre><pre class="alt">+      int fd = open(path, O_WRONLY);</pre><pre>+      <span class="kwrd">if</span> (fd != -1)</pre><pre class="alt">+        result = ftruncate(fd, size);</pre><pre>+      close(fd);</pre><pre class="alt">+      <span class="kwrd">return</span> result;</pre><pre>+    }</pre><pre class="alt">+<span class="rem">#else</span></pre><pre><span class="rem">#   define BOOST_RESIZE_FILE(P,SZ)(::truncate(P, SZ)== 0)</span></pre><pre class="alt">+<span class="rem">#endif</span></pre><pre>&nbsp;</pre><pre class="alt"><span class="rem">#   define BOOST_ERROR_NOT_SUPPORTED ENOSYS</span></pre><pre>#   define BOOST_ERROR_ALREADY_EXISTS EEXIST</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>&nbsp;</p>
<p>5. 命令行编译:
<p>./b2 --without-python --without-mpi --without-serialization toolset=gcc-android4.6 link=static runtime-link=static target-os=linux --stagedir=android
<p>使用编译完成的boost库
<p>1. 将编译boost_1_53_0\android\lib\ 下的.a库 及boost_1_53_0\boost\下的头文件拷贝出来放在工程的boost4android目录下
<p>2. 在boost4android目录下,创建Android.mk, 内容如下
<div class="csharpcode"><pre class="alt">LOCAL_PATH:= $(call my-dir)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_atomic</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_atomic.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_chrono</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_chrono.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_context</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_context.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_date_time</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_date_time.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_exception</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_exception.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_filesystem</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_filesystem.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_graph</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_graph.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_iostreams</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_iostreams.a </pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_math_c99</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_math_c99.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_math_c99f</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_math_c99f.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_math_c99l</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_math_c99l.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_math_tr1</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_math_tr1.a </pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_math_tr1f</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_math_tr1f.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_math_tr1l</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_math_tr1l.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_program_options</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_program_options.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_random</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_random.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre> </pre><pre class="alt">include $(CLEAR_VARS)</pre><pre>LOCAL_MODULE:= boost_regex</pre><pre class="alt">LOCAL_SRC_FILES:= lib/libboost_regex.a</pre><pre>LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre class="alt">include $(PREBUILT_STATIC_LIBRARY)</pre><pre>&nbsp;</pre><pre class="alt">&nbsp;</pre><pre>include $(CLEAR_VARS)</pre><pre class="alt">LOCAL_MODULE:= boost_system</pre><pre>LOCAL_SRC_FILES:= lib/libboost_system.a</pre><pre class="alt">LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre>include $(PREBUILT_STATIC_LIBRARY)</pre><pre class="alt"> </pre><pre>include $(CLEAR_VARS)</pre><pre class="alt">LOCAL_MODULE:= boost_thread</pre><pre>LOCAL_SRC_FILES:= lib/libboost_thread.a</pre><pre class="alt">LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre>include $(PREBUILT_STATIC_LIBRARY)</pre><pre class="alt"> </pre><pre>include $(CLEAR_VARS)</pre><pre class="alt">LOCAL_MODULE:= boost_timer</pre><pre>LOCAL_SRC_FILES:= lib/libboost_timer.a</pre><pre class="alt">LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)</pre><pre>include $(PREBUILT_STATIC_LIBRARY)</pre><pre class="alt"> </pre></div>
<div class="csharpcode">可以根据自己的需要调整以上包含</div>
<div class="csharpcode">&nbsp;</div>
<div class="csharpcode">3. 在应用程序的Android.mk中添加</div>
<p>LOCAL_WHOLE_STATIC_LIBRARIES += boost_system<br>LOCAL_WHOLE_STATIC_LIBRARIES += boost_filesystem<br>LOCAL_WHOLE_STATIC_LIBRARIES += boost_thread</p>
<p>用多少, 包多少</p>
<p>添加异常支持 LOCAL_CPPFLAGS += –fexceptions</p>
<p>&nbsp;</p>
<p>添加模块引用</p>
<p>$(call import-module,boost4android)
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style></p><img src ="http://www.cppblog.com/sunicdavy/aggbug/201993.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2013-07-20 16:23 <a href="http://www.cppblog.com/sunicdavy/archive/2013/07/20/201993.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Google Protocolbuf 文本格式的解析</title><link>http://www.cppblog.com/sunicdavy/archive/2013/07/09/201643.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Tue, 09 Jul 2013 10:29:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2013/07/09/201643.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/201643.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2013/07/09/201643.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/201643.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/201643.html</trackback:ping><description><![CDATA[<p>protobuf就是为懒人而造的工具, 啥协议, 啥配置文件, 统统定义proto, 解析就ok, 非常方便</p> <p>&nbsp;</p> <p>文本格式的解析错误不能使用捕获错误来获取, 因此,我们需要使用自定义的错误收集器进行收集, 看代码:</p> <div class="csharpcode"><pre class="alt">#include &lt;google/protobuf/text_format.h&gt;</pre><pre>#include &lt;google/protobuf/io/zero_copy_stream_impl_lite.h&gt;</pre><pre class="alt">#include &lt;google/protobuf/io/tokenizer.h&gt;</pre><pre>&nbsp;</pre><pre class="alt"><span class="kwrd">class</span> PBTextErrorCollector : <span class="kwrd">public</span> google::protobuf::io::ErrorCollector</pre><pre>{</pre><pre class="alt"><span class="kwrd">public</span>:</pre><pre>    PBTextErrorCollector( <span class="kwrd">const</span> std::<span class="kwrd">string</span>&amp; FileName )</pre><pre class="alt">        : mFileName( FileName )</pre><pre>    {</pre><pre class="alt">&nbsp;</pre><pre>    }</pre><pre class="alt">&nbsp;</pre><pre>    <span class="kwrd">virtual</span> <span class="kwrd">void</span> AddError(<span class="kwrd">int</span> line, <span class="kwrd">int</span> column, <span class="kwrd">const</span> <span class="kwrd">string</span>&amp; message)</pre><pre class="alt">    {</pre><pre>        CCLog(<span class="str">"%s(%d:%d) %s "</span>, mFileName.c_str(), line, column, message.c_str() );</pre><pre class="alt">    }</pre><pre>&nbsp;</pre><pre class="alt">    <span class="kwrd">virtual</span> <span class="kwrd">void</span> AddWarning(<span class="kwrd">int</span> line, <span class="kwrd">int</span> column, <span class="kwrd">const</span> <span class="kwrd">string</span>&amp; message) </pre><pre>    {</pre><pre class="alt">        CCLog(<span class="str">"%s(%d:%d) %s "</span>, mFileName.c_str(), line, column, message.c_str() );</pre><pre>    }</pre><pre class="alt">&nbsp;</pre><pre><span class="kwrd">private</span>:</pre><pre class="alt">    std::<span class="kwrd">string</span> mFileName;</pre><pre>};</pre><pre class="alt">&nbsp;</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>解析代码</p>
<div class="csharpcode"><pre class="alt">google::protobuf::TextFormat::Parser P;        </pre><pre>    P.RecordErrorsTo( &amp;PEC );</pre><pre class="alt">    P.Parse( &amp;AIS, &amp;AF );</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>&nbsp;</p>
<p>另外: 文本格式的注释使用unix shell风格: 以#开头</p>
<p>下面是我的文本格式的配置文件</p>
<p>&nbsp;</p><pre class="csharpcode">AnchorPointX: 0.5
AnchorPointY: 0

SpriteScale: 2

ComponentName: <span class="str">"ActorActionManager"</span>
ComponentName: <span class="str">"ActorFrameEventDispatcher"</span>
<span class="rem">#ComponentName: "SoundFXController"</span>
ComponentName: <span class="str">"RoleDeltaMoveController"</span>
ComponentName: <span class="str">"RoleBehaviorDirector"</span>

InitAction: AA_Idle

Animations 
{
  AnimationName: <span class="str">"mai_idle"</span>
  AnimationInterval: 0.067
}
</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style><img src ="http://www.cppblog.com/sunicdavy/aggbug/201643.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2013-07-09 18:29 <a href="http://www.cppblog.com/sunicdavy/archive/2013/07/09/201643.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>NDK中启用c++0x</title><link>http://www.cppblog.com/sunicdavy/archive/2013/07/01/201426.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Mon, 01 Jul 2013 08:09:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2013/07/01/201426.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/201426.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2013/07/01/201426.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/201426.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/201426.html</trackback:ping><description><![CDATA[<p>c++0x中已经添加了诸如function, bind等需要boost支持的功能, 不再需要编译复杂的boost了</p> <p>在你的Android.mk文件中添加 LOCAL_CPPFLAGS += -std=gnu++0x即可</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/201426.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2013-07-01 16:09 <a href="http://www.cppblog.com/sunicdavy/archive/2013/07/01/201426.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>程序异常VC调试器无法定位的处理</title><link>http://www.cppblog.com/sunicdavy/archive/2013/06/27/201339.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Thu, 27 Jun 2013 03:05:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2013/06/27/201339.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/201339.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2013/06/27/201339.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/201339.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/201339.html</trackback:ping><description><![CDATA[<p>最近调试程序发现空指针老无法定位, 使用一个最简单的main函数做空指针检查也一样, 具体症状见图</p> <p><a href="http://www.cppblog.com/images/cppblog_com/sunicdavy/Windows-Live-Writer/Visual-Studio_9AF3/image_2.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.cppblog.com/images/cppblog_com/sunicdavy/Windows-Live-Writer/Visual-Studio_9AF3/image_thumb.png" width="749" height="439"></a></p> <p>pdb加载是正常的, 但是堆栈没显示如此简单的空指针访问位置. Google了以下</p> <p><a href="http://blogs.msdn.com/b/debugger/archive/2010/05/12/visual-studio-debugger-fails-to-catch-unhandled-exception-for-a-windows-form-or-wpf-application.aspx">http://blogs.msdn.com/b/debugger/archive/2010/05/12/visual-studio-debugger-fails-to-catch-unhandled-exception-for-a-windows-form-or-wpf-application.aspx</a></p> <p>解决方法: Debug-&gt;Exception中将所有异常勾选即可</p> <p>&nbsp;</p> <p>不知道哪里的设置导致如此诡异的问题, 害的我重装一次..</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/201339.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2013-06-27 11:05 <a href="http://www.cppblog.com/sunicdavy/archive/2013/06/27/201339.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android平台下NDK编译protocolbuff例子</title><link>http://www.cppblog.com/sunicdavy/archive/2013/06/17/201070.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Mon, 17 Jun 2013 03:40:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2013/06/17/201070.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/201070.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2013/06/17/201070.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/201070.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/201070.html</trackback:ping><description><![CDATA[<p>先说下我的工程目录</p> <p>ProjectName\</p> <p>src\</p> <p>&nbsp; core\</p> <p>&nbsp; share\</p> <p>&nbsp; proj.android\</p> <p>&nbsp;&nbsp;&nbsp; jni\</p> <p>&nbsp;&nbsp;&nbsp; …</p> <p>sdk\</p> <p>&nbsp; protobuf-2.4.1\</p> <p>&nbsp;&nbsp;&nbsp; src\</p> <p>&nbsp;&nbsp;&nbsp; …</p> <p>从Google code下载protobuf-2.4.1源码包, 解压, 在protobuf-2.4.1目录下添加Android.mk, 内容如下</p>  <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">LOCAL_PATH := $(call my-<span style="color: #0000ff">dir</span>)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">include $(CLEAR_VARS)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">LOCAL_MODULE := protobuf-2.4.1</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">LOCAL_SRC_FILES := \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/io/coded_stream<span style="color: #cc6633">.cc</span>                \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/io/printer<span style="color: #cc6633">.cc</span>                     \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/io/gzip_stream<span style="color: #cc6633">.cc</span>                 \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/io/tokenizer<span style="color: #cc6633">.cc</span>                   \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/io/zero_copy_stream<span style="color: #cc6633">.cc</span>            \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/io/zero_copy_stream_impl<span style="color: #cc6633">.cc</span>       \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/io/zero_copy_stream_impl_lite<span style="color: #cc6633">.cc</span>  \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/stubs/common<span style="color: #cc6633">.cc</span>                   \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/stubs/once<span style="color: #cc6633">.cc</span>                     \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/stubs/structurally_valid<span style="color: #cc6633">.cc</span>       \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/stubs/strutil<span style="color: #cc6633">.cc</span>                  \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/stubs/substitute<span style="color: #cc6633">.cc</span>               \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/compiler/importer<span style="color: #cc6633">.cc</span>              \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/compiler/parser<span style="color: #cc6633">.cc</span>                \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/descriptor<span style="color: #cc6633">.cc</span>                     \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/descriptor<span style="color: #cc6633">.pb</span><span style="color: #cc6633">.cc</span>                  \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/descriptor_database<span style="color: #cc6633">.cc</span>            \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/dynamic_message<span style="color: #cc6633">.cc</span>                \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/extension_set<span style="color: #cc6633">.cc</span>                  \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/extension_set_heavy<span style="color: #cc6633">.cc</span>            \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/generated_message_reflection<span style="color: #cc6633">.cc</span>   \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/generated_message_util<span style="color: #cc6633">.cc</span>         \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/message<span style="color: #cc6633">.cc</span>                        \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/message_lite<span style="color: #cc6633">.cc</span>                   \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/reflection_ops<span style="color: #cc6633">.cc</span>                 \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/repeated_field<span style="color: #cc6633">.cc</span>                 \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/service<span style="color: #cc6633">.cc</span>                        \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/text_format<span style="color: #cc6633">.cc</span>                    \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/unknown_field_set<span style="color: #cc6633">.cc</span>              \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/wire_format<span style="color: #cc6633">.cc</span>                    \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">src/google/protobuf/wire_format_lite<span style="color: #cc6633">.cc</span>               \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">LOCAL_C_INCLUDES := $(LOCAL_PATH) \</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    $(LOCAL_PATH)/src</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                   </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">include $(BUILD_STATIC_LIBRARY)</pre><!--CRLF--></div></div>
<p>此时编译会报config.h找不到的错误, 这个文件在vsproject目录有, 但只是VC编译使用,&nbsp; 这篇<a href="http://blog.csdn.net/kaitiren/article/details/9047943">文章</a>说需要手动创建, 但实际上, Linux下可以通过config系统自动生成的, 但是Android平台下,不使用cygwin时, 就需要自己手动创建config.h, 内容如下</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #008000">/*</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #008000">    This make file is only for android ONLY, modified by Davy Xu June 17, 2013</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #008000">    Cause android platform can't use linux config system when cygwin envirement is not available</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #008000">*/</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #008000">/* the location of &lt;hash_set&gt; */</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">#define HASH_SET_H <span style="color: #006080">&lt;</span>ext/hash_set<span style="color: #006080">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">#define HASH_MAP_H <span style="color: #006080">&lt;</span>ext/hash_map<span style="color: #006080">&gt;</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">#define HASH_NAMESPACE __gnu_cxx</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #008000">/* define if the compiler has hash_map */</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #008000">//#define HAVE_HASH_MAP 1</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #008000">/* define if the compiler has hash_set */</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #008000">//#define HAVE_HASH_SET 1</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">#define HAVE_PTHREAD</pre><!--CRLF--></div></div>
<p>剩下的事情就简单了, 在你的工程Android.mk里添加protobuf的引用</p>
<p>例如:</p>
<p>LOCAL_WHOLE_STATIC_LIBRARIES += protobuf-2.4.1</p>
<p>$(call import-module,protobuf-2.4.1)</p>
<p>还要在NDK_MODULE_PATH中增加搜索路径D:\Develop\ProjectName\sdk\</p>
<p>注意, 这里protobuf-2.4.1名称必须与sdk下的文件夹名, LOCAL_MODULE中的名称保持一致, 否则搜索不到</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/201070.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2013-06-17 11:40 <a href="http://www.cppblog.com/sunicdavy/archive/2013/06/17/201070.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>最便捷的Android环境部署cocos2dx程序</title><link>http://www.cppblog.com/sunicdavy/archive/2013/06/09/200904.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sun, 09 Jun 2013 09:55:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2013/06/09/200904.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/200904.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2013/06/09/200904.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/200904.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/200904.html</trackback:ping><description><![CDATA[<p>本文整个部署过程无需下载及安装使用Cygwin环境， 以下部署过程需要用到的程序及版本  </p><p>请注意下载对应你系统的版本, 64位系统请保证后文全系使用64位程序, 以免遇到不必要的麻烦  </p><p>1.JDK&amp;JRE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JAVA运行时及开发包  </p><p>2.ADT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 是Eclipse的一个插件，这一步是为了管理安卓开发库  </p><p><a href="http://developer.android.com/sdk/index.html">http://developer.android.com/sdk/index.html</a>  </p><p>作为新手, 请下载ADT Bundle For Windows, 这个版本已经包含  </p><p>ADK（安卓开发包）, CDT（Eclipse的C/C++开发插件）及对应的Eclipse, 可以避免第一次部署出现的各种烦心!  </p><p>3.NDK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 只有ADT已经可以运行普通的Andriod程序，但是如果需要编译C/C++程序， 还需要NDK  </p><p><a href="http://developer.android.com/tools/sdk/ndk/index.html">http://developer.android.com/tools/sdk/ndk/index.html</a>  </p><p>4. cocos2dx 2.0.4版本  </p><p>&nbsp; </p><p><strong>准备SDK API</strong>  </p><p align="left">下载好ADT后解压， 有如下目录</p> <p>eclipse\&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;- 开发环境</p> <p>sdk\&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;- Andriod SDK</p> <p>SDK Manager.exe&nbsp;&nbsp;&nbsp;&nbsp; &lt;-- Android开发包管理器, 由于Andriod版本较多, 所以此管理器可以方便开发者选择部署目标机器</p> <p>打开SDK Manager在Android 2.2(API 8)里的 SDK Platform, Google APIs前打勾, 点击右下角的Instal packages</p> <p>如果感觉下载速度慢, 可以移步这里<a href="http://my.oschina.net/heguangdong/blog/17443">http://my.oschina.net/heguangdong/blog/17443</a>, 选择Andriod离线下载</p> <p>这里是下载链接</p> <p><a href="http://dl-ssl.google.com/android/repository/google_apis-8_r02.zip">http://dl-ssl.google.com/android/repository/google_apis-8_r02.zip</a></p> <p><a href="http://dl-ssl.google.com/android/repository/android-2.2_r02-windows.zip">http://dl-ssl.google.com/android/repository/android-2.2_r02-windows.zip</a></p> <p><a href="https://dl-ssl.google.com/android/repository/usb_driver_r04-windows.zip">https://dl-ssl.google.com/android/repository/usb_driver_r04-windows.zip</a></p> <p>把android开头的文件解压到platforms目录下</p> <p>把goole_apis开头的文件解压到add-ons目录下</p> <p align="left">把usb_driver_r03-windows.zip解压到usb_driver目录下。</p> <p><strong>Eclipse导入工程</strong>  </p><p>打开Eclipse</p> <p>导入Cocos2dx例子工程:</p> <p>Eclipse中File-&gt;New-&gt;Other...选择Andriod Project from Existing Code</p> <p>在Import Projects的Root Directory中导入D:\Develop\RevWar\sdk\cocos2d-2.0-x-2.0.4\samples\HelloCpp\proj.android\</p> <p><strong>注意, 不要选中 Copy project into workspace, 否则路径编乱很难编译成功</strong></p> <p align="left">&nbsp;</p> <p><strong>导入cocos2dx的java框架</strong>  </p><p>在src目录中new package, 输入org.cocos2dx.lib, 在org.cocos2dx.lib的package中点Import-&gt; FileSystem </p> <p>选中目录D:\Develop\RevWar\sdk\cocos2d-2.0-x-2.0.4\cocos2dx\platform\android\java\src\org\cocos2dx\lib\, 点选所有java文件</p> <p>工程Properties-&gt;Builder-&gt;New-&gt;Program</p> <p><strong>在Main标签中填写</strong></p> <p>填写NDK编译命令行 D:\Develop\android-ndk-r8e\ndk-build.cmd</p> <p>点击Browser Workspace选中当前工程,出现${workspace_loc:/HelloCpp}</p> <p><strong>切换到Environment标签中填写</strong></p> <p>新建NDK_MODULE_PATH 填写D:\Develop\RevWar\sdk\cocos2d-2.0-x-2.0.4\;D:\Develop\RevWar\sdk\cocos2d-2.0-x-2.0.4\cocos2dx\platform\third_party\android\prebuilt\</p> <p><strong>修改cocos2dx的Android.mk, diff如下</strong></p> <p>@@ -153,6 +153,7 @@</p> <p>LOCAL_WHOLE_STATIC_LIBRARIES += cocos_jpeg_static</p> <p>LOCAL_WHOLE_STATIC_LIBRARIES += cocos_libxml2_static</p> <p>LOCAL_WHOLE_STATIC_LIBRARIES += cocos_libtiff_static</p> <p>+LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static</p> <p># define the macro to compile through support/zip_support/ioapi.c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p> <p>LOCAL_CFLAGS := -DUSE_FILE32API</p> <p>@@ -164,3 +165,4 @@</p> <p>$(call import-module,libpng)</p> <p>$(call import-module,libxml2)</p> <p>$(call import-module,libtiff)</p> <p>+$(call import-module,CocosDenshion/android)</p> <blockquote></blockquote> <p><strong>F&amp;Q</strong></p> <p><strong>andriod-8问题</strong></p> <p>修改D:\Develop\RevWar\sdk\cocos2d-2.0-x-2.0.4cocos2dx\platform\android\java\project.properties中的target=android-8改成你需要的版本</p> <p><strong>resources.ap_ does not exist </strong></p> <p>assert目录中有资源出问题, 排查即可</p> <p>例如: cocos2d-2.0-x-2.0.4\samples\TestCpp\proj.android\assets\Images\*.pvr.gz</p> <p><strong>启动Android模拟器时的Failed to allocate memory: 8问题</strong></p> <p>调整内存值,请求内存太大导致</p> <p><strong>api版本过低导致JAVA Symbol未定义问题</strong></p> <p>setEGLContextClientVersion undefined</p> <p>api8(andriod 2.2)后的版本, 才支持openGL es 2.0</p> <p><strong>自己做工程遇到的问题D:\Develop\RevWar\sdk\cocos2d-2.0-x-2.0.4\/cocos2dx/platform/android/jni/JniHelper.h:28:18: fatal error: string: No such file or directory</strong></p> <p>将cocos2dx例子中的Application.mk拷过来, 修改下内部名称即可</p> <p><strong>调试请尽量使用真机, 模拟器速度很慢</strong></p><strong> <p><strong></strong><strong>小米2默认只能管理文件, 无法用adb 连接, 因此需要安装驱动, USB驱动直接在插入电脑后的虚拟盘里找.. 这个太坑了..</strong></p></strong><strong> <p><strong></strong><strong>保证每次都能部署最新的程序</strong></p></strong> <p>请执行每次Clean, Build project, Debug.&nbsp; 真机上在需要时, 会弹出安装...</p> <p><strong>Android启动日志</strong></p> <p>带有ADT的Eclipse中有一个logcat窗口, 里面有系统及程序本身的日志, 可以做过滤,方便检查问题. 如需自己打日志, 可以使用cocos2dx中的LOGD宏来做, 原型是__android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)</p> <p>&nbsp;</p> <p><strong>Remark</strong>  </p><p>添加assert后, F5刷新后再编译<br />NDK build时,默认从工程的jni目录开始  </p><p>Andriod.mk的import 原则$(call import-module,模块名) 这里的模块名必须与目录名, 模块make file中的名称报纸一致  </p><p><strong>参考文章</strong>  </p><p><a href="http://www.cnblogs.com/ybgame/archive/2012/06/07/2540693.html">http://www.cnblogs.com/ybgame/archive/2012/06/07/2540693.html</a>  </p><p>发文时, Andriod Studio已经发布了一段时间, 虽然是测试版, 但将代表未来更方便的Andriod发布工具</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/200904.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2013-06-09 17:55 <a href="http://www.cppblog.com/sunicdavy/archive/2013/06/09/200904.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Lua使用protocolbuf</title><link>http://www.cppblog.com/sunicdavy/archive/2013/04/24/199693.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Wed, 24 Apr 2013 07:44:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2013/04/24/199693.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/199693.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2013/04/24/199693.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/199693.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/199693.html</trackback:ping><description><![CDATA[<p>在<a href="https://code.google.com/p/protoc-gen-lua/">https://code.google.com/p/protoc-gen-lua/</a> 下载网易兄弟写的lua的protobuf插件(网易都把pb给弄完了,as3的也是他们写的..)</p> <p>&nbsp;</p> <p><strong>编译python版的protobuf模块</strong></p> <p>在<a href="https://code.google.com/p/protobuf/downloads/list">https://code.google.com/p/protobuf/downloads/list</a> 下载官方的原生版本protobuf, 这里发文时使用的是2.4.1版本</p> <p>编译出protoc执行文件, 放一份在protobuf-2.4.1\src\下</p> <p>下载python2.7版本, 在protobuf-2.4.1\python下运行python setup.py install(如果找不到python请给python绝对路径)</p> <p>这一步, python会下一个蛋( 真的是一个python的egg文件 ), 然后编译出python版本的protobuf模块放置在python下</p> <p>&nbsp;</p> <p><strong>制作protoc-gen-lua的批处理</strong></p> <p>放一份protoc在protoc-gen-lua的plugin目录</p> <p>编写批处理:protoc-gen-lua.bat</p> <p>@python "%~dp0protoc-gen-lua"</p> <p>&nbsp;</p> <p><strong>协议目录生成脚本</strong></p> <p>在你需要放置协议的目录编写如下批处理</p> <p>buildproto.bat</p> <p>rd /S /Q .\%1%<br />"..\..\src\protoc-gen-lua\plugin\protoc.exe" --plugin=protoc-gen-lua="..\..\src\protoc-gen-lua\plugin\protoc-gen-lua.bat" --lua_out=. %1%.proto</p> <p>注意protoc.exe及protoc-gen-lua.bat的路径符合你的路径</p> <p>再编写要编译的proto协议的批处理generate.bat</p> <p>call buildproto.bat loginsvc</p> <p>执行generate.bat后, 将会编译同目录下的loginsvc.proto,输出loginsvc_pb.lua</p> <p>&nbsp;</p> <p><strong>编译链接lua的pb库</strong></p> <p>将protoc-gen-lua\protobuf\目录拷贝到之前的协议目录</p> <p>将其下的pb.c链入你的工程, 注意VS2010的VC下需要修改源码</p> <p>1.将 #include &lt;endian.h&gt;修改为</p> <p>#ifndef _WIN32<br />&nbsp;&nbsp;&nbsp;&nbsp; #include &lt;endian.h&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; #endif</p> <p>避免在windows下缺失文件报错.</p> <p>2. 调整struct_unpack函数前几行为</p> <p>static int struct_unpack(lua_State *L)<br />{<br />&nbsp;&nbsp;&nbsp; uint8_t format = luaL_checkinteger(L, 1);<br />&nbsp;&nbsp;&nbsp; size_t len;<br />&nbsp;&nbsp;&nbsp; const uint8_t* buffer = (uint8_t*)luaL_checklstring(L, 2, &amp;len);<br />&nbsp;&nbsp;&nbsp; size_t pos = luaL_checkinteger(L, 3);<br />&nbsp;&nbsp;&nbsp; uint8_t out[8];&nbsp;&nbsp;&nbsp; </p> <p>&nbsp;&nbsp;&nbsp; buffer += pos; </p> <p>避免VS2010的VC编译器过于标准, 严格要求C风格函数变量前置声明</p> <p>在lua_State声明后添加如下代码</p> <p>extern "C" { int luaopen_pb (lua_State *L);}&nbsp;&nbsp; // 注意防在命名空间外的全局声明</p> <p>&nbsp;&nbsp;&nbsp; luaopen_pb( L );&nbsp;&nbsp; // 直接注入全局pb, 避免动态加载pb.dll造成的一系列跨平台问题</p> <p>&nbsp;</p> <p><strong>lua中使用pb</strong></p> <p class="csharpcode"></p><pre class="alt"><span class="kwrd">local</span> loginsvc_pb = require &#8220;loginsvc_pb&#8221;</pre><pre>&nbsp;</pre><pre class="alt"><span class="kwrd">local</span> REQ = loginsvc_pb.CheckVersionREQ()</pre><pre><span class="kwrd">local</span> Data = REQ:SerializeToString( )</pre><pre class="alt">&nbsp;</pre><pre><span class="kwrd">local</span> ACK = loginsvc_pb.CheckVersionACK()</pre><pre class="alt">ACK:ParseFromString( Data )</pre><p>&nbsp;</p>
<p>
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

</p>
<p>我的工程目录</p>
<p>script\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protobuf\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; buildproto.bat<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; generate.bat<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; loginsvc_pb.lua<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; loginsvc.proto<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Main.lua<br />&nbsp;&nbsp;&nbsp; src\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protoc-gen-lua\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; example\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; plugin\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protobuf\</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/199693.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2013-04-24 15:44 <a href="http://www.cppblog.com/sunicdavy/archive/2013/04/24/199693.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>捕获Linux段错误(Segment fault)并且打印错误堆栈</title><link>http://www.cppblog.com/sunicdavy/archive/2012/12/29/196809.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sat, 29 Dec 2012 09:53:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/12/29/196809.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/196809.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/12/29/196809.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/196809.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/196809.html</trackback:ping><description><![CDATA[<p>Linux上跑服务器如果遇到程序崩溃是一件很苦恼的事情, 再碰到重现很难的BUG, 估计只能通过传统的排查方法进行.</p> <p>在编写本文前, 笔者使用过诸如libunwind等库进行错误时堆栈打印, 但是其本身由于需要引用第三方库, 使用还是稍微麻烦.</p> <p>经过Google后, 居然找到一篇<a href="http://blog.csdn.net/kakaka2011/article/details/6597857">好文</a>, 其通过捕获SIGSEGV信号, 并迫使程序进入gdb调试阶段, 利用gdb强大的调试功能可以进行各种错误跟踪, 此法已与Windows下程序崩溃后弹出VC调试几乎接近. </p> <p>我在此文基础上, 扩展了其通用性及便利性</p> <p>1. 使用gdb的 -ex参数, 在挂接程序后, 执行bt指令打出程序堆栈</p> <p>2. 将信息重定向到自定义的文件,在多进程都需要进行后台输出时带来更大的灵活性, 同时也解决了gdb只能在前台调试的问题</p> <p>代码如下</p><pre class="csharpcode">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;signal.h&gt;
#include &lt;<span class="kwrd">string</span>.h&gt;

<span class="kwrd">void</span> dump(<span class="kwrd">int</span> signo)
{
        <span class="kwrd">char</span> buf[1024];
        <span class="kwrd">char</span> cmd[1024];
        FILE *fh;

        snprintf(buf, <span class="kwrd">sizeof</span>(buf), <span class="str">"/proc/%d/cmdline"</span>, getpid());
        <span class="kwrd">if</span>(!(fh = fopen(buf, <span class="str">"r"</span>)))
                exit(0);
        <span class="kwrd">if</span>(!fgets(buf, <span class="kwrd">sizeof</span>(buf), fh))
                exit(0);
        fclose(fh);
        <span class="kwrd">if</span>(buf[strlen(buf) - 1] == <span class="str">'/n'</span>)
                buf[strlen(buf) - 1] = <span class="str">'/0'</span>;
        snprintf(cmd, <span class="kwrd">sizeof</span>(cmd), <span class="str">"gdb %s %d -ex=bt &gt; ./a.txt"</span>, buf, getpid());
        system(cmd);

        exit(0);
}</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>在服务器开启时,添加 signal(SIGSEGV, &amp;dump ); 进行信号处理挂接即可</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>引用: <a title="http://blog.csdn.net/kakaka2011/article/details/6597857" href="http://blog.csdn.net/kakaka2011/article/details/6597857">http://blog.csdn.net/kakaka2011/article/details/6597857</a>&nbsp; 作者: kakaka2011</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/196809.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2012-12-29 17:53 <a href="http://www.cppblog.com/sunicdavy/archive/2012/12/29/196809.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>恼人的boost::asio::async_read_until</title><link>http://www.cppblog.com/sunicdavy/archive/2012/12/03/195921.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Mon, 03 Dec 2012 07:12:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/12/03/195921.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/195921.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/12/03/195921.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/195921.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/195921.html</trackback:ping><description><![CDATA[<p>最近为服务器添加XMLSocket与Flash进行通信, 这种协议其实是一种以\0结尾的字符串协议, 为了让asio兼容此协议, 我从文档找到了async_read_until异步读取系列, 这个函数的原理时, 给定一个streambuf, 和一个分隔符, asio碰到分隔符时返回, 你可以从streambuf中读取需要的数据. 看似很简单, 我很快写好一个demo与Flash进行通信, 结果发现在一个echo逻辑速度很快时, 服务器居然乱包了, 网上查了下, 官方原文是这样的:</p> <p>”After a successful async_read_until operation, the streambuf may contain additional data beyond the delimiter. An application will typically leave that data in the streambuf for a subsequent async_read_until operation to examine.”</p> <p>意思是, streambuf中并不一定是到分隔符前的所有数据, 多余的数据可能一样会在streambuf中. 也就是说, 还需要自己再次处理一遍数据...</p> <p>动手呗, async_read_until看似就是一个废柴, 底层已经费了很多CPU在逐字符与分隔符的匹配上, 抛上来的数据居然还是半成品.</p> <p>代码如下, 测试通过, 但是实在很费解为啥非要再做一次..</p><pre class="csharpcode">          boost::asio::streambuf* SB = SBP.get();

            <span class="rem">// 访问缓冲</span>
            <span class="kwrd">const</span> <span class="kwrd">char</span>* Buffs = boost::asio::buffer_cast&lt;<span class="kwrd">const</span> <span class="kwrd">char</span>*&gt;( SB-&gt;data() );

            uint32 DataSize = 0;
            <span class="kwrd">for</span> ( uint32 i = 0; i &lt; SB-&gt;size(); ++i )
            {
                <span class="kwrd">const</span> <span class="kwrd">char</span> DChar = Buffs[i];

                <span class="rem">// 这里需要自己判断字符串内容, read_until的文档里这么说的</span>
                <span class="kwrd">if</span> ( DChar == <span class="str">'\0'</span> )
                {
                    DataSize = i;
                    <span class="kwrd">break</span>;
                }
            }

            <span class="kwrd">if</span> ( DataSize &gt; 0 )
            {
                <span class="rem">// 取成字符串</span>
                std::<span class="kwrd">string</span> FullText( Buffs, DataSize );
                
                <span class="rem">// 消费</span>
                SB-&gt;consume( DataSize );                

                mWorkService-&gt;post(
                    boost::bind(&amp;AsioSession::NotifyReadString,
                    shared_from_this(),
                    FullText )
                    );

            }</pre><pre class="csharpcode"><font size="2" face="Verdana">  另外, 为了保证输入性安全, 可以在streambuf构造时加一个最大一个读取量, 超过此量会返回报错, 避免了缓冲区被撑爆的危险</font></pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style><img src ="http://www.cppblog.com/sunicdavy/aggbug/195921.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2012-12-03 15:12 <a href="http://www.cppblog.com/sunicdavy/archive/2012/12/03/195921.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>切换Qt版本, 修改$(QTDIR)指向</title><link>http://www.cppblog.com/sunicdavy/archive/2012/07/14/183384.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sat, 14 Jul 2012 07:35:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/07/14/183384.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/183384.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/07/14/183384.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/183384.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/183384.html</trackback:ping><description><![CDATA[<p>最近从Qt4.7.0 升级到 Qt4.8.2, 装好了新的open sdk, 但是观察工程中的引用依旧是4.7.0</p> <p>在Windows环境变量中没有找到$(QTDIR)</p> <p>随即在Qt的Visual Studio 插件菜单中, Qt-&gt;Qt Options-&gt; Qt Versions</p> <p>设置Default Qt/Win version为新版本</p> <p>选中原有的Qt工程, 在插件菜单中找到Qt Project Settings-&gt;Properties-&gt;Version中,将版本设置为最新版本</p> <p>如果装有Visual AssitX, 此时这东西应该开始Parse新的Qt库了</p> <p>have fun <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="微笑" src="http://www.cppblog.com/images/cppblog_com/sunicdavy/Windows-Live-Writer/Qt_D9F5/wlEmoticon-smile_2.png">!</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/183384.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2012-07-14 15:35 <a href="http://www.cppblog.com/sunicdavy/archive/2012/07/14/183384.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MySQL++操作MySQL中造成Commands out of sync的2014错误分析</title><link>http://www.cppblog.com/sunicdavy/archive/2012/06/13/178678.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Wed, 13 Jun 2012 09:57:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/06/13/178678.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/178678.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/06/13/178678.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/178678.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/178678.html</trackback:ping><description><![CDATA[<p>MySQL++在MySQL原始C接口上做了一些封装, 给操作带来很大便利.</p> <p>最近遇到DB服务器中报出一个MySQL的错误:Commands out of sync; you can't run this command now,2014</p> <p>查阅很多代码, 解决方法都是使用C接口的方式, 模仿其解决方法,在MySQL++中找到了比较好的解决方案:</p> <p><strong>方案A</strong>: 清空每次未使用的记录</p><pre class="csharpcode"><span class="kwrd">for</span> (<span class="kwrd">int</span> i = 1; DataQuery.more_results(); ++i)
{
   DataQuery.store_next();                
}</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>其中 DataQuery类型为mysqlpp::Query</p>
<p>&nbsp;</p>
<p><strong>方案B</strong>: 对于存储过程中,使用了多个select语句返回同样的列结果, 就需要使用以下语句</p>
<div class="csharpcode"><pre class="alt"><span class="kwrd">static</span> <span class="kwrd">void</span> print_multiple_results(Query&amp; query)</pre><pre>{</pre><pre class="alt">    <span class="rem">// 执行查询并输出结果表</span></pre><pre> StoreQueryResult res = query.store();</pre><pre class="alt"> print_result(res, 0);</pre><pre> <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 1; query.more_results(); ++i) {</pre><pre class="alt">  res = query.store_next();</pre><pre>  print_result(res, i);</pre><pre class="alt"> }</pre><pre>}</pre><pre>&nbsp;</pre><pre>参考文章:<a href="http://hi.baidu.com/freeknight/item/ea9fd88e7d291f854514cf43">http://hi.baidu.com/freeknight/item/ea9fd88e7d291f854514cf43</a></pre></div><img src ="http://www.cppblog.com/sunicdavy/aggbug/178678.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2012-06-13 17:57 <a href="http://www.cppblog.com/sunicdavy/archive/2012/06/13/178678.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]Lisp的永恒之道</title><link>http://www.cppblog.com/sunicdavy/archive/2012/06/12/178505.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Tue, 12 Jun 2012 04:38:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/06/12/178505.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/178505.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/06/12/178505.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/178505.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/178505.html</trackback:ping><description><![CDATA[<h5>本文转自: <a href="http://coolshell.cn/articles/7526.html">http://coolshell.cn/articles/7526.html</a></h5> <p>&nbsp;</p> <h5>Lisp之魅</h5> <p>长久以来，Lisp一直被许多人视为史上最非凡的编程语言。它不仅在50多年前诞生的时候带来了诸多革命性的创新并极大地影响了后来编程语言的发展，即使在一大批现代语言不断涌现的今天，Lisp的诸多特性仍然未被超越。当各式各样的编程语言摆在面前，我们可以从运行效率、学习曲线、社区活跃度、厂商支持等多种不同的角度进行评判和选择，但我特别看中的一点在于语言能否有效地表达编程者的设计思想。学习C意味着学习如何用过程来表达设计思想，学习Java意味着学习如何用对象来表达设计思想，而虽然Lisp与函数式编程有很大的关系，但学习Lisp绝不仅仅是学习如何用函数表达设计思想。实际上，<strong>函数式编程并非Lisp的本质</strong>，在已经掌握了lambda、高阶函数、闭包、惰性求值等函数式编程概念之后，学习Lisp仍然大大加深了我对编程的理解。<strong>学习Lisp所收获的是如何“自由地”表达你的思想</strong>，这正是Lisp最大的魅力所在，也是这门古老的语言仍然具有很强的生命力的根本原因。 <h5>Lisp之源</h5> <p>Lisp意为表处理(List Processing)，源自设计者John McCarthy于1960年发表的一篇论文《符号表达式的递归函数及其机器计算》。McCarthy在这篇论文中向我们展示了用一种简单的数据结构S表达式(S-expression)来表示代码和数据，并在此基础上构建一种完整的语言。Lisp语言形式简单、内涵深刻，Paul Graham在《Lisp之根源》中将其对编程的贡献与欧几里德对几何的贡献相提并论。 <h5>Lisp之形</h5> <p>然而，与数学世界中简单易懂的欧氏几何形成鲜明对比，程序世界中的Lisp却一直是一种古老而又神秘的存在，真正理解其精妙的人还是少数。从表面上看，Lisp最明显的特征是它“古怪”的S表达式语法。S表达式是一个原子(atom)，或者若干S表达式组成的列表(list)，表达式之间用空格分开，放入一对括号中。“列表“这个术语可能会容易让人联想到数据结构中的链表之类的线形结构，实际上，Lisp的列表是一种可嵌套的树形结构。下面是一些S表达式的例子:<pre>foo

()

(a b (c d) e)

(+ (* 2 3) 5)

(defun factorial (N)
    (if (= N 1)
        1
        (* N (factorial (- N 1)))
    )
)
</pre>
<p>据说，这个古怪的S表达式是McCarthy在发明Lisp时候所采用的一种临时语法，他实际上是准备为Lisp加上一种被称为M表达式(M-expression)的语法，然后再把M表达式编译为S表达式。用一个通俗的类比，S表达式相当于是JVM的字节码，而M表达式相当于Java语言，但是后来Lisp的使用者都熟悉并喜欢上了直接用S表达式编写程序，并且他们发现S表达式有许多独特的优点，所以M表达式的引入也就被无限期延迟了。
<p>许多Lisp的入门文章都比较强调Lisp的函数式特性，而我认为这是一种误导。真正的Lisp之门不在函数式编程，而在S表达式本身，Lisp最大的奥秘就藏在S表达式后面。S表达式是Lisp的语法基础，语法是语义的载体，形式是实质的寄托。<strong>“S表达式”是程序的一种形，正如“七言”是诗的一种形，“微博”是信息的一种形</strong>。正是形的不同，让微博与博客有了质的差异，同样的道理，正是S表达式让Lisp与C、Java、SQL等语言有了天壤之别。
<h5>Lisp之道</h5>
<p>一门语言能否有效地表达编程者的设计思想取决于其抽象机制的语义表达能力。根据抽象机制的不同，语言的抽象机制形成了面向过程、面向对象、函数式、并发式等不同的范式。当你采用某一种语言，基本上就表示你已经“面向XXX“了，你的思维方式和解决问题的手段就会依赖于语言所提供的抽象方式。比如，采用Java语言通常意味着采用面向对象分析设计；采用Erlang通常意味着按Actor模型对并发任务进行建模。
<p>有经验的程序员都知道，无论是面向XXX编程，程序设计都有一条“抽象原则“：What与How解耦。但是，<strong>普通语言的问题就在于表达What的手段非常有限</strong>，无非是过程、类、接口、函数等几种方式，而诸多领域问题是无法直接抽象为函数或接口的。比如，你完全可以在C语言中定义若干函数来做到make file所做的事情，但C代码很难像make file那样声明式地体现出target、depends等语义，它们只会作为实现细节被淹没在一个个的C函数之中。采用OOP或是FP等其它范式也会遇到同样的困难，也就是说make file语言所代表的抽象维度与面向过程、OOP以及FP的抽象维度是正交的，使得各种范式无法直接表达出make file的语义。这就是普通语言的“刚性”特征，它要求我们必须以语言的抽象维度去分析和解决问题，把问题映射到语言的基本语法和语义。
<p>更进一步，如果仔细探究这种刚性的根源，我们会发现正是由于普通语言<strong>语法和语义的紧耦合</strong>造成了这种刚性。比如，C语言中printf(“hello %s”, name)符合函数调用语法，它表达了函数调用语义，除此之外别无他义；Java中interface IRunnable { … }符合接口定义语法，它表达了接口定义语义，除此之外别无他义。如果你认为“语法和语义紧耦合“是理所当然的，看不出这有什么问题，那么理解Lisp就会让你对此产生更深的认识。
<p>当你看到Lisp的(f a (b c))的时候，你会想到什么？会不会马上联想到函数求值或是宏扩展？就像在C语言里看到gcd(10, 15)马上想到函数调用，或者在Java里看到class A马上想到类定义一样。如果真是这样，那它就是你理解Lisp的一道障碍，因为你已经习惯了顺着语言去思考，总是在想这一句话机器怎么解释执行？那一句话又对应语言的哪个特性？理解Lisp要反过来，让语言顺着你，Lisp的(f a (b c))可以是任何语义，完全由你来定，它可以是函数定义、类定义、数据库查询、文件依赖关系，异步任务的执行关系，业务规则 …
<p>下面我准备先通过几个具体的例子逐步展示Lisp的本质。需要说明的是，由于Lisp的S表达式和XML的语法形式都是一种树形结构，在语义表达方面二者并无本质的差别。所以，为了理解方便，下面我暂且用多数人更为熟悉的XML来写代码，请记住我们可以很轻易地把XML代码和Lisp代码相互转换。
<p>首先，我们可以轻易地用XML来定义一个求两个数最大公约数的函数：<pre>    &lt;func name='gcd' return_type='int'&gt;
        &lt;params&gt;
            &lt;a type='int'/&gt;
            &lt;b type='int'/&gt;
        &lt;/params&gt;
        &lt;body&gt;
            &lt;if&gt;
               &lt;equals&gt;
                   &lt;a/&gt;
                   &lt;int&gt;0&lt;/int&gt;
               &lt;/equals&gt;
            &lt;/if&gt;
            &lt;then&gt;
                &lt;return&gt;&lt;b/&gt;&lt;/return&gt;
            &lt;/then&gt;
            &lt;else&gt;
                &lt;return&gt;
                    &lt;gcd&gt;
                        &lt;modulo&gt;&lt;b/&gt;&lt;a/&gt;&lt;/modulo&gt;
                        &lt;a/&gt;
                    &lt;/gcd&gt;
                &lt;/return&gt;
            &lt;/else&gt;
        &lt;/body&gt;
    &lt;/func&gt;
</pre>
<p>其次，我们可以用它来定义类：<pre>    &lt;class name="Computer"&gt;
        &lt;field access="private" type="MainBoard" name="main-board" /&gt;
        &lt;field access="private" type="CPU" name="cpu" /&gt;
        &lt;field access="private" type="Memory" name="memory" /&gt;

        &lt;method access="public" return_type="boolean" name="powerOn" /&gt;
            &lt;params&gt;...&lt;/params&gt;
            &lt;body&gt;...&lt;/body&gt;
        &lt;/method&gt;

        &lt;method access="public" return_type="boolean" name="powerOff" /&gt;
            &lt;params&gt;...&lt;/params&gt;
            &lt;body&gt;...&lt;/body&gt;
        &lt;/method&gt;
    &lt;/class&gt;
</pre>
<p>还可以轻易地用它来编写关系查询：<pre>&lt;sql&gt;
    &lt;select&gt;
        &lt;column name="employees.id" /&gt;
        &lt;column name="bonus.amount" /&gt;
    &lt;/select&gt;
    &lt;from&gt;
        &lt;table name="employees" /&gt;
        &lt;table name="bonus" /&gt;
    &lt;/from&gt;
    &lt;where&gt;
        &lt;equals&gt;
            &lt;column name="employees.id" /&gt;
            &lt;column name="bonus.employee_id" /&gt;
        &lt;/equals&gt;
    &lt;/where&gt;
&lt;/sql&gt;
</pre>
<p>还可以用它来实现类似make file的自动化构建(语法取自ant)：<pre>    &lt;project name="MyProject" default="dist" basedir="."&gt;
        &lt;property name="src" location="src"/&gt;
        &lt;property name="build" location="build"/&gt;
        &lt;property name="dist"  location="dist"/&gt;

        &lt;target name="init"&gt;
            &lt;mkdir dir="${build}"/&gt;
        &lt;/target&gt;

        &lt;target name="compile" depends="init" description="compile the source " &gt;
            &lt;javac srcdir="${src}" destdir="${build}"/&gt;
        &lt;/target&gt;

        &lt;target name="dist" depends="compile" description="generate the distribution" &gt;
            &lt;mkdir dir="${dist}/lib"/&gt;
            &lt;jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/&gt;
        &lt;/target&gt;

        &lt;target name="clean" description="clean up" &gt;
            &lt;delete dir="${build}"/&gt;
            &lt;delete dir="${dist}"/&gt;
        &lt;/target&gt;
    &lt;/project&gt;
</pre>
<p>一口气举了这么多个例子，目的在于用XML这种树形结构来说明Lisp的S表达式所能够描述的语义。不知道你是否发现了S表达式和XML这种树形语法在语义构造方面有着特别的“柔性”？我们可以轻易地用它构造出函数、变量、条件判断语义；类、属性、方法语义；可以轻易地构造出关系模型的select、where语义；可以轻易地构造出make的target、depends语义，等等数不清的语义。在普通语言里，你可以定义一个函数、一个类，但你无法为C语言增加匿名函数特性，也没法给Java语言加上RAII语义，甚至连自己创造一个foreach循环都不行，而自定义语义意味着在Lisp之上<strong>你创造了一门语言</strong>！不管是面向过程，面向对象，函数式，还是关系模型，在Lisp里统统都变成了一种DSL，而Lisp本身也就成了一种定义语言的语言，即元语言(Meta Language)。
<p>Lisp的柔性与S表达式有着密切的关系。Lisp并不限制你用S表达式来表达什么语义，同样的S表达式语法可以表达各种不同领域的语义，这就是<strong>语法和语义解耦</strong>。如果说普通语言的刚性源于“语法和语义紧耦合”，那么Lisp的柔性正是源于“语法和语义解耦”！“语法和语义解耦”使得Lisp可以随意地构造各种领域的DSL，而不强制用某一种范式或是领域视角去分析和解决问题。本质上，Lisp编程是一种超越了普通编程范式的范式，这就是<strong>Lisp之道：面向语言编程(LOP, Language Oriented Programming)</strong>。Wikipedia上是这样描述LOP的：
<blockquote>
<p>Language oriented programming (LOP) is a style of computer programming in which, rather than solving problems in general-purpose programming languages, the programmer creates one or more domain-specific languages for the problem first, and solves the problem in those languages … The concept of Language Oriented Programming takes the approach to capture requirements in the user’s terms, and then to try to create an implementation language as isomorphic as possible to the user’s descriptions, so that the mapping between requirements and implementation is as direct as possible.</p></blockquote>
<p>LOP范式的基本思想是从问题出发，先创建一门描述领域模型的DSL，再用DSL去解决问题，它具有高度的声明性和抽象性。SQL、make file、CSS等DSL都可以被认为是LOP的具体实例，下面我们再通过两个常见的例子来理解LOP的优势。
<p>例1：在股票交易系统中，交易协议定义若干二进制的消息格式，交易所和客户端需要对消息进行编码和解码。
<p>消息格式是一种抽象的规范，本身不对语言做任何的限制，你可以用C，C++，Java，或者Python。普通的实现方式是按照消息格式规范，在相应的语言中定义消息结构，并编写相应的编解码函数。假设为一个消息定义结构和实现编解码函数的工作量为M，不同消息类型的数量为N，这种方式的工作量大致为M*N。也就是说每增加一种消息类型，就需要为该消息定义结构，实现编解码函数，引入bug的可能性当然也和M*N成正比。如果仔细观察不难发现，各个消息结构其实是高度类似的，编解码函数也大同小异，但是普通语言却找不到一种抽象机制能表达这种共性，比如，我们无法通过面向对象的方法定义一个基类把消息结构的共性抽象出来，然后让具体的消息去继承它，达到复用的目的。这正是由于普通语言的抽象维度限制所致，在普通语言中，你只能从函数、接口等维度对事物进行抽象，而恰好消息格式共性所在的维度与这些抽象维度并不匹配。
<p>其实，不同消息类型的<strong>共性在于它们都具有相同的领域语义</strong>，比如：“某字段内容是另一个字段内容的md5码”就是一种消息格式的领域语义，这种领域语义是OOP的抽象机制无法描述的。LOP的思路是先创建一门消息定义DSL，比如，类似Google的Protocol Buffer，Android的AIDL。然后，通过DSL编写消息定义文件，直接声明式地描述消息的结构特征，比如，我们可以声明式地描述“某字段内容是另一个字段内容的md5码”。我们还需要为DSL开发编译器用于生成C、Java等通用语言的消息定义和编解码函数。
<p>有了消息定义DSL和编译器之后，由于DSL编写消息定义是一种高度声明式的编程方法，每增加一种消息的只需要多编写一个消息定义文件而已，工作量几乎可以忽略不计。所有的工作量都集中在编译器的开发上，工作量是一个常数C，与消息的数量没有关系；质量保证方面也只需要关注编译器这一点，不会因为增加新的消息类型而引入bug。
<p>例2：在图书管理系统中，需要支持在管理界面上对书籍、学生、班级等各种实体进行管理操作。
<p>如果按传统的三层架构，一般需要在后端程序中为每一种实体定义一个类，并定义相应的方法实现CRUD操作，与之相应的，还需要在前端页面中为每一个实体编写相应的管理页面。这些实体类的CRUD操作都是大同小异的，但细节又各不相同，虽然我们很想复用某些共同的设计实现，但OOP所提供的封装、继承、多态等抽象机制不足以有效捕获实体之间的共性，大量的代码还是必须放在子类中来完成。比如，Student和Book实体类的实现非常相似，但是如果要通过OOP的方式去抽象它们的共性，得出的结果多半是Entity这样的大而空的基类，很难起到复用的效果。
<p>其实，不同实体之间的共性还是在于它们具有相同的领域语义，比如：实体具有属性，属性具有类型，属性具有取值范围，属性具有可读取、可编辑等访问属性，实体之间有关联关系等。LOP方法正是直接面向这种领域语义的。采用LOP方法，我们并不需要为每一个实体类单独编写CRUD方法，也不需要单独编写管理页面，只需要定义一种DSL并实现其编译器；然后，用DSL声明式地编写实体描述文件，去描述实体的属性列表，属性的类型、取值范围，属性所支持的操作，属性之间的关系和约束条件等；最后，通过这个实体描述文件自动生成后端的实体类和前端管理页面。采用LOP，不论前后端采用何种技术，Java也好，C#也好，JSP也好，ASP.NET也好，都可以自动生成它们的代码。采用LOP的工作量和质量都集中在DSL的设计和编译器的开发，与实体的数量无关，也就是说，越是庞大的系统，实体类越多越是能体现LOP的优势。
<p>通过上面两个小例子我们可以感受到，LOP是一种面向领域的，高度声明式的编程方式，它的抽象维度与领域模型的维度完全一致。LOP能让程序员从复杂的实现细节中解脱出来，把关注点集中在问题的本质上，从而提高编程的效率和质量。
<p>接下来的问题是如果需要为某领域设计DSL，我们是应该发明一门类似SQL这样的专用DSL呢，还是用XML或S表达式去定义DSL呢？它们各有何优缺点呢？
<p>我认为采用XML或S表达式定义DSL的优点主要有：1) SQL、make file、CSS等专用DSL都只能面向各自的领域，而一个实际的领域问题通常是跨越多个领域的，有时我们需要将不同领域融合在一起，但是由于普通语言的刚性，多语言融合通常会是一件非常困难的事情，而XML和S表达式语法结构的单一性和“代码及数据”的特点使得跨领域融合毫无障碍。2) 在为DSL开发编译器或解释器的方面，二者难度不同。对XML和S表达式定义的DSL进行语法分析非常简单，相比之下，对SQL这样的专用DSL进行语法分析，虽然可以借助Lex、Yacc、ANTLR等代码生成工具，但总的来讲复杂度还是要明显高一些。
<p>当然，XML和S表达式的优点也正好是其缺点，由于XML和S表达式的语法形式是固定的，不能像专用DSL那样自由地设计语法。所以，一般来讲专用DSL的语法显得更加简洁。换句话说，XML和Lisp其实是在语法和语义间做了一个交换，用语法的限制换来了语义的灵活。
<h5>Lisp之器</h5>
<p>接下来我们继续探讨DSL的解释执行问题。DSL代码的解释执行一般分为3种典型的方式：1) 通过专门的解释器解释执行；2) 编译生成其他语言的代码，再通过其他语言的解释器解释执行(或编译运行)；3) 自解释。比如，第1类的代表是SQL，上一节举的两个例子都属于第2类，而第3类自解释正是Lisp的特色。
<p>为了理解自解释，我们可以先从内部DSL的解释执行说起。内部DSL是指嵌入在宿主语言中的DSL，比如，Google Test单元测试框架定义了一套基于流畅接口(Fluent Interface)的C++单元测试DSL。从语义构造的角度看，内部DSL直接借用宿主语言的语法定义了自己的领域语义，是一种语法和语义解耦；从解释执行的角度看，内部DSL是随宿主语言的解释器而自动解释的，不需要像外部DSL一样开发专门的解释器，因而实现的代价很低。当然，并不是说设计内部DSL不用关心任何的解释实现，实际上，还是需要熟悉宿主语言的特性，并利用该特性使得DSL能随着宿主语言的解释器得到解释执行。
<p>Lisp拥有强大的自解释特性，这得益于独一无二的<strong>Lisp之器：宏 (macro)</strong>。宏使得Lisp编写的DSL可以被Lisp解释器直接解释执行，这在原理上与内部DSL是相通的，只是内部DSL一般是利用宿主语言的链式调用等特性，通常形式简陋，功能有限，而Lisp的宏则要强大和灵活得多。
<p>C语言中也有宏的概念，不过Lisp的宏与C语言的宏完全不同，C语言的宏是简单的字符串替换。比如，下面的宏定义：<pre>#define square(x) (x*x)
</pre>
<p>square(1+1)的期望结果是4，而实际上它会被替换成(1+1*1+1)，结果是3。这个例子说明，C语言的宏只在预编译阶段进行简单的字符串替换，对程序语法结构缺乏理解，非常脆弱。Lisp的宏不是简单的字符串替换，而是一套完整的代码生成系统，它是在语法解析的基础上把Lisp代码从一种形式转换为另一种形式，本质上起到了普通语言编译器的作用。不同的是，普通编译器是把一种语言的代码转换为另一种语言的代码，比如，Java编译器把Java代码转换成Java字节码；而Lisp宏的输入和输出都是S表达式，它本质上是把一种DSL转换为另一种DSL。下面的例子是宏的一个典型用法。
<p>例3：假设Lisp解释器已经具备解释执行面向过程DSL的能力，需要实现类似ant的自动化构建工具。
<p>我们可以基于宏构建一门类ant的DSL，宏的作用是把类ant DSL通过宏展开变成面向过程的DSL，最后被Lisp解释器所解释执行。这样用Lisp编写的ant DSL就不需要被编译为其他语言，也不需要像XML的ant一样依赖于专门的解释器了。
<p>当然，和开发专门的解释器/编译器相比，Lisp的宏也并非没有缺点，宏难以理解，开发和调试更加困难。到底是开发专门的解释器/编译器还是直接采用宏应该视具体情况而定。
<h5>总结</h5>
<p>Lisp采用单一的S表达式语法表达不同的语义，实现了语法和语义解耦。这使得Lisp具有强大的语义构造能力，擅长于构造DSL实现面向语言编程，而宏使得Lisp具有自解释能力，让不同DSL之间的转换游刃有余。进入Lisp的世界应当从理解面向语言编程入门，这是Lisp之道，而函数式编程和宏皆为Lisp之器，以道驭器方为正途。
<h5>后记</h5>
<p>本文是我学习Lisp的一个总结，也是写给有兴趣学习Lisp的程序员的入门资料。必须说明，我还是一个标准的Lisp初学者，几乎没有写过像样的Lisp程序，文中的错误和不足在所难免，希望读者批评指正，感谢！
<h5>参考</h5>
<p><a href="http://www.paulgraham.com/rootsoflisp.html">The Roots of Lisp</a>
<p><a href="http://www.defmacro.org/ramblings/lisp.html">The Nature of Lisp</a>
<p><a href="http://lists.warhead.org.uk/pipermail/iwe/2005-July/000130.html">Why Lisp macros are cool, a Perl perspective</a>
<p><a href="http://en.wikipedia.org/wiki/Language-oriented_programming">Wikipedia: Language-oriented programming</a>
<p><a href="http://book.douban.com/subject/6859720/">《实用Common Lisp编程》</a>
<p><a href="http://book.douban.com/subject/4031906/">《冒号课堂 – 编程范式与OOP思想》</a></p><img src ="http://www.cppblog.com/sunicdavy/aggbug/178505.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2012-06-12 12:38 <a href="http://www.cppblog.com/sunicdavy/archive/2012/06/12/178505.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>log4cpp在Linux编译的错误解决方法</title><link>http://www.cppblog.com/sunicdavy/archive/2012/04/21/172261.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sat, 21 Apr 2012 08:43:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/04/21/172261.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/172261.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/04/21/172261.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/172261.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/172261.html</trackback:ping><description><![CDATA[<p>BasicLayout.cpp:37:5: error: 'auto_ptr' in namespace 'std' does not name a type</p> <p>在包含中添加#include &lt;memory&gt;即可</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/172261.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2012-04-21 16:43 <a href="http://www.cppblog.com/sunicdavy/archive/2012/04/21/172261.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>生成mysql++静态库</title><link>http://www.cppblog.com/sunicdavy/archive/2012/04/20/172142.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Fri, 20 Apr 2012 06:48:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/04/20/172142.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/172142.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/04/20/172142.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/172142.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/172142.html</trackback:ping><description><![CDATA[<p>由于服务器需要静态链接所有库,但mysql++默认编译使用的是共享库, 因此使用ar手动生成一个</p> <p>mysql++版本3.1.0</p> <p>进入mysql++目录,执行以下指令生成libmysqlpp.a</p> <p>ar rcu libmysqlpp.a mysqlpp_beemutex.o mysqlpp_cmdline.o mysqlpp_connection.o mysqlpp_cpool.o mysqlpp_datetime.o mysqlpp_dbdriver.o mysqlpp_field_names.o mysqlpp_field_types.o mysqlpp_manip.o mysqlpp_myset.o mysqlpp_mysql++.o mysqlpp_mystring.o mysqlpp_null.o mysqlpp_options.o mysqlpp_qparms.o mysqlpp_query.o mysqlpp_result.o mysqlpp_row.o mysqlpp_scopedconnection.o mysqlpp_sql_buffer.o mysqlpp_sqlstream.o mysqlpp_ssqls2.o mysqlpp_stadapter.o mysqlpp_tcp_connection.o mysqlpp_transaction.o mysqlpp_type_info.o mysqlpp_uds_connection.o mysqlpp_utility.o mysqlpp_vallist.o mysqlpp_wnp_connection.o ssqls2parse_parsev2.o</p> <p>然后mv到usr/local/lib,重新链接服务器即可</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/172142.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2012-04-20 14:48 <a href="http://www.cppblog.com/sunicdavy/archive/2012/04/20/172142.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>让C/C++程序一次编译可以发布到多版本Linux之上</title><link>http://www.cppblog.com/sunicdavy/archive/2012/04/20/172108.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Fri, 20 Apr 2012 03:35:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/04/20/172108.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/172108.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/04/20/172108.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/172108.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/172108.html</trackback:ping><description><![CDATA[<p>最近页游开放平台比较多, 每个平台要求的Linux版本各不相同, 这给开发人员部署服务器带来了很大的困难. 在本机Linux编译的程序,发布时即便将依赖的so附带到目标Linux环境,仍然会碰到依赖及版本问题,例如:</p> <p><font face="Lucida Console">[root@localhost bin]# ldd wkcenter <br /><font color="#ff0000">./wkcenter: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by ./wkcenter)<br />./wkcenter: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by ./wkcenter)<br />./wkcenter: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by ./wkcenter)<br />./wkcenter: /lib/libc.so.6: version `GLIBC_2.9' not found (required by ./wkcenter)<br />./wkcenter: /lib/libc.so.6: version `GLIBC_2.7' not found (required by ./wkcenter)<br />./wkcenter: /lib/libc.so.6: version `GLIBC_2.8' not found (required by ./wkcenter)<br />./wkcenter: /lib/libc.so.6: version `GLIBC_2.11' not found (required by ./wkcenter)</font><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linux-gate.so.1 =&gt;&nbsp; (0xffffe000)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; liblog4cpp.so.4 =&gt; not found<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libprotobuf.so.7 =&gt; not found<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libboost_filesystem.so.1.48.0 =&gt; not found<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libboost_system.so.1.48.0 =&gt; not found<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libboost_thread.so.1.48.0 =&gt; not found<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libboost_program_options.so.1.48.0 =&gt; not found<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libunwind-x86.so.7 =&gt; not found<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libluabind.so.0.9.0 =&gt; not found<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libstdc++.so.6 =&gt; /usr/lib/libstdc++.so.6 (0x008ae000)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libm.so.6 =&gt; /lib/libm.so.6 (0x0044b000)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libgcc_s.so.1 =&gt; /lib/libgcc_s.so.1 (0x00476000)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libc.so.6 =&gt; /lib/libc.so.6 (0x002c1000)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libpthread.so.0 =&gt; /lib/libpthread.so.0 (0x0041d000)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; librt.so.1 =&gt; /lib/librt.so.1 (0x00440000)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /lib/ld-linux.so.2 (0x002a2000)</font><br /></p> <p>上面红字部分表示glibc及glibcxx库依赖不正确. 本人使用的Linux编译版本为Mint 11(基于Ubuntu), 一般Ubuntu发行版的glibc配备非常高. 但是上文中的发布的Linux版本为CentOS 5.8</p> <p>使用/lib/libc.so.6 查看libc版本为2.5, 远远低于开发环境的2.11</p> <p><font face="Lucida Console">GNU C Library stable release version <font color="#ff0000">2.5</font>, by Roland McGrath et al.<br />Copyright (C) 2006 Free Software Foundation, Inc.<br />This is free software; see the source for copying conditions.<br />There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A<br />PARTICULAR PURPOSE.<br />Compiled by GNU CC version 4.1.2 20080704 (Red Hat 4.1.2-51).<br />Compiled on a Linux 2.6.9 system on 2012-02-21.<br />Available extensions:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The C stubs add-on version 2.1.2.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; crypt add-on version 2.1 by Michael Glad and others<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GNU Libidn by Simon Josefsson<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GNU libio by Per Bothner<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Native POSIX Threads Library by Ulrich Drepper et al<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BIND-8.2.3-T5B<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RT using linux kernel aio<br />Thread-local storage support included.<br />For bug reporting instructions, please see:<br />&lt;</font><a href="http://www.gnu.org/software/libc/bugs.html"><font face="Lucida Console">http://www.gnu.org/software/libc/bugs.html</font></a><font face="Lucida Console">&gt;.</font></p> <p><font face="Lucida Console">由于Linux操作系统的特有elf加载顺序. (可以参考<a href="http://www.iteedu.com/os/linux/mklinuxdiary/ch4mksystem/4.php">此文</a>). 虽然可以很大程度上解决Windows早期版本的dll hell问题, 但是给部署带来了很大难度</font></p> <p><font face="Lucida Console">一般常见的解决方法是, 找到一个与目标Linux版本及glibc版本一致的Linux, 将代码及依赖包放在之上编译, 完成后再发布.这种方法与Linux下常见软件安装方法类似. 但是对于商用服务器部署步骤来说未免繁琐, 安全性低.</font></p> <p>还有一种方法,使用静态链接. 将所有可执行文件文件依赖的静态库, 系统库,全部静态链接到可执行文件中,可以一次性解决这个问题</p> <p>步骤:</p> <p>&nbsp;&nbsp;&nbsp; 1. 在gcc链接命令行中添加-static -static-libgcc -static-libstdc++</p> <p>&nbsp;&nbsp;&nbsp; 2. 将第三方依赖库打开静态链接开关, 将原来链接.so的库,全改为链接.a</p> <p>&nbsp;&nbsp;&nbsp; 3. gcc对链接库顺序很敏感, 链接库顺序需要按照从前至后为:&nbsp; 项目产生的静态库 &gt; 第三方库静态库 &gt; 系统静态库</p> <p>&nbsp;&nbsp;&nbsp; 4. 链接时, 若有未解决的symbol, 可以尝试在最后添加-lpthread及-lrt解决</p> <p>&nbsp;&nbsp;&nbsp; </p> <p>在发布版本Linux上运行可能遇到的问题:</p> <p><font face="Lucida Console">terminate called after throwing an instance of 'std::runtime_error'</font> </p><p><font face="Lucida Console">what(): locale::facet::_S_create_c_locale name not valid</font> </p><p>解决方法: 执行之前运行export LC_ALL="C"  </p><img src ="http://www.cppblog.com/sunicdavy/aggbug/172108.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2012-04-20 11:35 <a href="http://www.cppblog.com/sunicdavy/archive/2012/04/20/172108.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>luabind实现lua中的取对象大小功能</title><link>http://www.cppblog.com/sunicdavy/archive/2012/03/27/169178.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Tue, 27 Mar 2012 09:36:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/03/27/169178.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/169178.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/03/27/169178.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/169178.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/169178.html</trackback:ping><description><![CDATA[<p>在lua中, #操作符用于获取对象大小, 对于table来说, 获取的是table元素个数, 对于字符串来说获取的是字符串长度</p> <p>另外一种获取方法是table.getn(obj), 但是这个方法已经标记为废除了, 尽量使用通用且简洁的#操作符</p> <p>&nbsp;</p> <p>使用lua api实现此功能就需要用到lua_objlen( ),但是这个功能未在luabind中提供.所以我们顺手添加一个</p> <p>首先找到luabind源码的object.hpp中取对象类型的type函数,在其下添加以下代码</p> <p>&nbsp;</p><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">  1: <span style="color: #0000ff">template</span>&lt;<span style="color: #0000ff">class</span> ValueWrapper&gt;</pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">  2: <span style="color: #0000ff">inline</span> <span style="color: #0000ff">int</span> obj_size(ValueWrapper <span style="color: #0000ff">const</span>&amp; value)</pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">  3: {</pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">  4:     lua_State* interpreter = value_wrapper_traits&lt;ValueWrapper&gt;::interpreter(</pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">  5:         value</pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">  6:         );</pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">  7: </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">  8:     value_wrapper_traits&lt;ValueWrapper&gt;::unwrap(interpreter, value);</pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">  9:     detail::stack_pop pop(interpreter, 1);</pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 10:     <span style="color: #0000ff">return</span> lua_objlen(interpreter, -1);</pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 11: }</pre><p>&nbsp;</p></pre> 重新编译你的代码, 就可以这样使用luabind::obj_size( obj ) 获取对象大小了<img src ="http://www.cppblog.com/sunicdavy/aggbug/169178.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2012-03-27 17:36 <a href="http://www.cppblog.com/sunicdavy/archive/2012/03/27/169178.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>luabind使用coroutine时的一处善意提示导致的BUG</title><link>http://www.cppblog.com/sunicdavy/archive/2012/03/27/169110.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Tue, 27 Mar 2012 02:38:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/03/27/169110.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/169110.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/03/27/169110.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/169110.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/169110.html</trackback:ping><description><![CDATA[<p>以下代码使用luabind进行lua的coroutine测试</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">void</span> ScriptManagedChannel::OnServiceInitialize()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {    </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     <span style="color: #0000ff">try</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     {        </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>         mThread = lua_newthread( GScriptScriptContext-&gt;GetVM() );</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>&nbsp; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>         luabind::resume_function&lt;<span style="color: #0000ff">void</span>&gt;( mThread, <span style="color: #006080">"ScriptMain"</span>, <span style="color: #0000ff">this</span> );</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>&nbsp; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>         Resume();</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>     }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>     <span style="color: #0000ff">catch</span> (std::exception&amp; e)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>     {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>         <span style="color: #0000ff">const</span> <span style="color: #0000ff">char</span>* ErrorMsg = lua_tostring( GScriptScriptContext-&gt;GetVM(), -1 );            </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span>         printf(<span style="color: #006080">"%s\n"</span>, e.what() );</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15">  15:</span>     }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16">  16:</span>&nbsp; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17">  17:</span>     </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18">  18:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19">  19:</span>&nbsp; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20">  20:</span> <span style="color: #0000ff">void</span> ScriptManagedChannel::Resume( )</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21">  21:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum22">  22:</span>     luabind::resume&lt;<span style="color: #0000ff">void</span>&gt;( mThread );</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum23">  23:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum24">  24:</span>&nbsp; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum25">  25:</span> <span style="color: #0000ff">void</span> ScriptManagedChannel::StopTest( )</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum26">  26:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum27">  27:</span>     lua_yield( mThread, 0 );</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum28">  28:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum29">  29:</span>&nbsp; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum30">  30:</span>&nbsp; </pre><!--CRLF--></div></div>
<p>代码中, mThread类型为lua_State*类型</p>
<p>GScriptScriptContext-&gt;GetVM()是加载了代码的lua_State*</p>
<p>StopTest为注册为ScriptManagedChannel类成员函数到lua中的定义</p>
<p>接下来看lua端的测试代码:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">function</span> ScriptMain( Channel )</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span>&nbsp; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     <span style="color: #0000ff">for</span> i = 1, 5 do</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>     </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>     <span style="color: #0000ff">print</span>("done", i)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>     </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>     Channel:StopTest( )</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>     </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>     </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>     </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>     <span style="color: #0000ff">end</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span> end</pre><!--CRLF--></div></div>
<p>刚开始,在测试代码时, lua中有个手误而造成的错误, 导致C++代码运行到第7行时弹出assert</p>
<p>位于:luabind-0.9.1\luabind\detail\call_function.hpp 第264行,对应以下代码第13行</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> ~proxy_function_void_caller()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     <span style="color: #0000ff">if</span> (m_called) <span style="color: #0000ff">return</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&nbsp; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>     m_called = true;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>     lua_State* L = m_state;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>&nbsp; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>     <span style="color: #0000ff">int</span> top = lua_gettop(L);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>&nbsp; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>     push_args_from_tuple&lt;1&gt;::apply(L, m_args);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>     <span style="color: #0000ff">if</span> (m_fun(L, boost::tuples::length&lt;Tuple&gt;::value, 0))</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>     {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>         assert(lua_gettop(L) == top - m_params + 1);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span>&nbsp; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15">  15:</span> NO_EXCEPTIONS</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16">  16:</span>         <span style="color: #0000ff">throw</span> luabind::error(L);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17">  17:</span> <span style="color: #cc6633">#else</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18">  18:</span>         error_callback_fun e = get_error_callback();</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19">  19:</span>         <span style="color: #0000ff">if</span> (e) e(L);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20">  20:</span>     </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21">  21:</span>         assert(0 &amp;&amp; <span style="color: #006080">"the lua function threw an error and exceptions are disabled."</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum22">  22:</span>                 <span style="color: #006080">" If you want to handle the error you can use luabind::set_error_callback()"</span>);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum23">  23:</span>         std::terminate();</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum24">  24:</span> <span style="color: #cc6633">#endif</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum25">  25:</span>     }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum26">  26:</span>     <span style="color: #008000">// pops the return values from the function call</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum27">  27:</span>     stack_pop pop(L, lua_gettop(L) - top + m_params);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum28">  28:</span> }</pre><!--CRLF--></div></div>
<p>11行代码中调用的是lua_resume, 返回的是运行错误, 但是被13行的assert挡住了, 无法通过第16行抛出异常被外面捕获.</p>
<p>因此,<strong>尝试注释第13行</strong>, 再测试, 可以在lua抛出错误后, 在栈顶捕获到coroutine函数resume时报出的错误信息.问题解决</p>
<p>&nbsp;</p>
<p>对于lua的coroutine, 网上资料不多, 这里有一篇比较详细的<a href="http://klcommon.googlecode.com/svn/trunk/collections/docs/lua_coroutine.txt">代码</a></p>
<p>我比较疑惑的是, 有没有必要将代码在dofile或者dobuffer时, 必须传入newthread出的state? 如果还是传入原始的state会有什么影响?</p>
<p>欢迎各位有此经验的讨论</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/169110.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2012-03-27 10:38 <a href="http://www.cppblog.com/sunicdavy/archive/2012/03/27/169110.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>