﻿<?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++博客-战魂小筑-随笔分类-脚本技术</title><link>http://www.cppblog.com/sunicdavy/category/11293.html</link><description>讨论群:309800774 知乎关注:http://zhihu.com/people/sunicdavy 开源项目:https://github.com/davyxu</description><language>zh-cn</language><lastBuildDate>Mon, 27 Dec 2021 17:00:58 GMT</lastBuildDate><pubDate>Mon, 27 Dec 2021 17:00:58 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>Go语言与构造函数</title><link>http://www.cppblog.com/sunicdavy/archive/2016/12/01/214457.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Thu, 01 Dec 2016 02:45:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2016/12/01/214457.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/214457.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2016/12/01/214457.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/214457.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/214457.html</trackback:ping><description><![CDATA[<p style="margin-right: 0px; margin-bottom: 10px; margin-left: 0px; font-size: 15px; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; line-height: 24px; widows: 1; margin-top: 0px !important;">Golang中没有设计构造函数. 取而代之的, 设计Golang的大师希望你用普通函数去实现构造的任务.&nbsp;<br />一直只是觉得这只是体现Golang这门新语言的精简设计之道, 直到自己实现编译器后才发现构造函数的设计本身是值得商榷的</p><p style="margin: 10px 0px; font-size: 15px; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; line-height: 24px; widows: 1;">我们先看下构造函数的规则</p><h1>构造函数调用规则</h1><p style="margin: 10px 0px; font-size: 15px; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; line-height: 24px; widows: 1;">构造参数量: 0表示没有构造函数, 1表示有构造函数0个参数</p><table style="margin: 10px 0px; border-collapse: collapse; border-style: solid; border-color: #bbbbbb; padding: 0px; color: #000000; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; font-size: 15px; line-height: 24px; widows: 1;"><thead><tr style="border-top-width: 1px; border-top-style: solid; border-top-color: #cccccc; margin: 0px; padding: 0px; background-color: white;"><th style="padding: 6px 13px; border-collapse: collapse; border: 1px solid #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">本类构造</th><th style="padding: 6px 13px; border-collapse: collapse; border: 1px solid #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">父类构造</th><th style="padding: 6px 13px; border-collapse: collapse; border: 1px solid #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">处理方法</th></tr></thead><tbody><tr style="border-top-width: 1px; border-top-style: solid; border-top-color: #cccccc; margin: 0px; padding: 0px; background-color: white;"><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">0</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">0</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">不处理</td></tr><tr style="border-top-width: 1px; border-top-style: solid; border-top-color: #cccccc; margin: 0px; padding: 0px; background-color: #f8f8f8;"><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">1</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">0</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">调本类ctor</td></tr><tr style="border-top-width: 1px; border-top-style: solid; border-top-color: #cccccc; margin: 0px; padding: 0px; background-color: white;"><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">0</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">1</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">调父类ctor</td></tr><tr style="border-top-width: 1px; border-top-style: solid; border-top-color: #cccccc; margin: 0px; padding: 0px; background-color: #f8f8f8;"><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">1</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">1</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">调本类ctor, 本类ctor调父类ctor</td></tr><tr style="border-top-width: 1px; border-top-style: solid; border-top-color: #cccccc; margin: 0px; padding: 0px; background-color: white;"><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">2</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">1</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">调本类ctor, 本类ctor调父类ctor</td></tr><tr style="border-top-width: 1px; border-top-style: solid; border-top-color: #cccccc; margin: 0px; padding: 0px; background-color: #f8f8f8;"><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">1</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">2</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">报错, 手动调父类ctor</td></tr><tr style="border-top-width: 1px; border-top-style: solid; border-top-color: #cccccc; margin: 0px; padding: 0px; background-color: white;"><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">2</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">2</td><td style="padding: 6px 13px; border-collapse: collapse; border-style: solid; border-color: #cccccc; height: 28px; word-break: break-all; box-sizing: border-box; outline: none; margin: 0px; font-size: 14px;">报错, 手动调父类ctor</td></tr></tbody></table><h1>普通函数重载规则</h1><p style="margin: 10px 0px; font-size: 15px; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; line-height: 24px; widows: 1;">实际只用考虑最典型的一种行为: 实例化子类, 转为父类调用方法, 这个时候</p><p style="margin: 10px 0px; font-size: 15px; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; line-height: 24px; widows: 1;">如果方法是override, 调用的是子类</p><p style="margin: 10px 0px; font-size: 15px; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; line-height: 24px; widows: 1;">如果方法是virutal或者不指明, 调用的是父类</p><p style="margin: 10px 0px; font-size: 15px; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; line-height: 24px; widows: 1;">整个重载过程, 子类绝对不会隐式调用父类的行为</p><h1>需要构造函数么?</h1><p style="margin: 10px 0px; font-size: 15px; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; line-height: 24px; widows: 1;">构造函数的优点</p><ul style="margin: 10px 0px; padding-left: 32px; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; font-size: 15px; line-height: 24px; widows: 1;"><li style="margin: 0px 0px 5px;">本身属于一种特殊的成员函数</li><li style="margin: 5px 0px;">编译器帮你自动传导调用父级</li></ul><p style="margin: 10px 0px; font-size: 15px; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; line-height: 24px; widows: 1;">构造函数的缺点</p><ul style="margin: 10px 0px; padding-left: 32px; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; font-size: 15px; line-height: 24px; widows: 1;"><li style="margin: 0px 0px 5px;">隐式的调用规则</li><li style="margin: 5px 0px;">虽然属于成员函数, 但是与其他成员函数调用规则完全不同, 需要特殊记忆</li><li style="margin: 5px 0px;">带参数的构造函数, 在父类参数多于子类时, 需要引用复杂语法来实现父级构造调用</li></ul><p style="margin: 10px 0px; font-size: 15px; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; line-height: 24px; widows: 1;">其实我们对初始化函数的需求只有1条: 自定义</p><p style="margin-top: 10px; margin-right: 0px; margin-left: 0px; font-size: 15px; font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif; line-height: 24px; widows: 1; margin-bottom: 0px !important;">所以, 可以理解Golang不加入构造函数的设计是正确的&nbsp;<br />即: 简单, 清晰, 有规律</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/214457.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-12-01 10:45 <a href="http://www.cppblog.com/sunicdavy/archive/2016/12/01/214457.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ulua结合protoc-gen-lua的几个坑</title><link>http://www.cppblog.com/sunicdavy/archive/2016/05/31/213612.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Tue, 31 May 2016 03:26:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2016/05/31/213612.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/213612.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2016/05/31/213612.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/213612.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/213612.html</trackback:ping><description><![CDATA[<p>最近整合ulua到项目里进行热更新, protoc-gen-lua这古老的东西重新让我继续发博客, 因为坑</p> <h2>生成好的协议报错找不到protobuf</h2> <p>在每个protoc-gen-lua生成的lua文件里, 都有一行</p><pre class="csharpcode">local protobuf = require <span class="str">"protobuf"</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>

<p>本身按照官方出的没问题, 但是在ulua的目录里, 总是报protobuf找不到的错误. 前后对比了下我生成的lua和ulua官方生成的代码里</p>
<p>发现居然他修改了地址改为了</p><pre class="csharpcode">local protobuf = require <span class="str">"protobuf/protobuf"</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>

<p>好吧, 只有修改生成器代码protoc-gen-lua\plugin\protoc-gen-lua中第412行改为</p><pre class="csharpcode">lua(<span class="str">'local protobuf = require "protobuf/protobuf"\n'</span>)</pre><pre class="csharpcode">&nbsp;</pre>
<h2>生成消息无法找到Descriptor反射查信息</h2><pre class="csharpcode">在LuaFramework\ToLua\Lua\protobuf\protobuf.lua的939行添加</pre><pre class="csharpcode">message_meta._member.Descriptor = descriptor</pre><pre class="csharpcode">在消息里就可以通过msg.Descriptor获得此消息的反射信息</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>

<h2>由于proto文件定义的内容过多导致的lua local超过限制的警告</h2>
<p><a href="http://www.cppblog.com/images/cppblog_com/sunicdavy/Windows-Live-Writer/proto_9D23/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/proto_9D23/image_thumb.png" width="800" height="76"></a></p>
<p>这个错误真是让我哭笑不得, protoc-gen-lua的可用性再一次被怀疑</p>
<p>我们的协议好歹分成了接近100个, 每个里面消息和数据是混合的, 更别说有些童鞋喜欢把一个项目的协议全写在一个文件里, 那生成的local数量简直是酸爽</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>后记</p>
<p>搜索protoc-gen-lua时, 无意间又搜到3年前自己的博文<a title="http://www.cppblog.com/sunicdavy/archive/2013/04/24/199693.html" href="http://www.cppblog.com/sunicdavy/archive/2013/04/24/199693.html">http://www.cppblog.com/sunicdavy/archive/2013/04/24/199693.html</a></p>
<p>记得那个时候准备在服务器使用lua, 还好没这么干, 转了go, 否则后果不堪设想</p>
<p>lua上使用pb其实并不容易, 云风的pbc写的不错, 但怕有坑, sproto直接不兼容现有项目, 风险大于易用性所以果断弃用</p>
<p>因此, 看来有必要自己写一个支持良好的lua pb库</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/213612.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-05-31 11:26 <a href="http://www.cppblog.com/sunicdavy/archive/2016/05/31/213612.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Golang, Lua, C#闭包变量捕获差异</title><link>http://www.cppblog.com/sunicdavy/archive/2015/09/23/211895.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Wed, 23 Sep 2015 10:31:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2015/09/23/211895.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/211895.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2015/09/23/211895.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/211895.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/211895.html</trackback:ping><description><![CDATA[<p>看C#例子</p> <div class="csharpcode"><pre class="alt">            Action[] a = <span class="kwrd">new</span> Action[3];</pre><pre>&nbsp;</pre><pre class="alt">            <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; 3; i++)</pre><pre>            {</pre><pre class="alt">                a[i] = ( ) =&gt; { Console.WriteLine(i); };</pre><pre>            }</pre><pre class="alt">&nbsp;</pre><pre>            <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; 3; i++){</pre><pre class="alt">                a[i]();</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>C#打印结果为3 3 3</p>
<p>&nbsp;</p>
<p>Golang的例子</p>
<div class="csharpcode"><pre class="alt">    a := make([]func(), 3 )</pre><pre>    </pre><pre class="alt">    <span class="kwrd">for</span> i := 0; i &lt; 3; i++ {</pre><pre>        </pre><pre class="alt">        a[i]= func( ){</pre><pre>            </pre><pre class="alt">            fmt.Println(i)</pre><pre>            </pre><pre class="alt">        }    </pre><pre>    </pre><pre class="alt">    }</pre><pre>    </pre><pre class="alt">    <span class="kwrd">for</span> _, s := range a {</pre><pre>        s()</pre><pre class="alt">    }</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>Golang打印结果为3 3 3</p>
<p>&nbsp;</p>
<p>最后是Lua的例子</p>
<div class="csharpcode"><pre class="alt">a = {}</pre><pre>&nbsp;</pre><pre class="alt"><span class="kwrd">for</span> i = 1, 3 <span class="kwrd">do</span></pre><pre>&nbsp;</pre><pre class="alt">    table.insert( a, function()</pre><pre>        print(i)</pre><pre class="alt">    end</pre><pre>    )</pre><pre class="alt">&nbsp;</pre><pre>end</pre><pre class="alt">&nbsp;</pre><pre>&nbsp;</pre><pre class="alt"><span class="kwrd">for</span> _, v <span class="kwrd">in</span> ipairs(a) <span class="kwrd">do</span></pre><pre>    v()</pre><pre class="alt">end</pre></div>
<p>Lua打印结果为1 2 3</p>
<p>&nbsp;</p>
<p>差异在于, C#和Golang将变量捕获到闭包内时, 均使用引用方式, 即当最后开始调用使用变量时, 由于变量已经结束循环, 所以是最终值</p>
<p>但是Lua捕获方式是值捕获, 因此比较容易理解, 是多少就是多少</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/211895.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2015-09-23 18:31 <a href="http://www.cppblog.com/sunicdavy/archive/2015/09/23/211895.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>深入挖掘protobuf: 通过protoc获取proto文件信息</title><link>http://www.cppblog.com/sunicdavy/archive/2015/03/01/209894.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sun, 01 Mar 2015 05:49:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2015/03/01/209894.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/209894.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2015/03/01/209894.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/209894.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/209894.html</trackback:ping><description><![CDATA[<p><strong>准备:</strong></p> <p>在<a title="http://code.google.com/p/protobuf/" href="http://code.google.com/p/protobuf/">http://code.google.com/p/protobuf/</a>下载protobuf-2.5版本</p> <p>预备知识: 已经使用过protobuf, 熟练应用protobuf序列化在各语言间交互信息</p> <p>目标: 获取proto内容而无需手动解析proto文件</p> <p>为proto文件添加更多的meta信息, 并在运行期获取.</p> <p>&nbsp;</p> <p><strong>protoc编译器准备</strong></p> <p>通过protobuf-2.5的源码或者从官网下载, 可以获得protoc的protobuf编译器, 这个编译器由C++编写, 官方支持完整的protobuf特性. 编译器默认支持C++, python和java 三种语言的代码生成. 如需生成更多的语言, 可以通过官网的第三方页面获取.</p> <p>&nbsp;</p> <p><strong>protoc插件原理</strong></p> <p>但我们在日常使用中, 可能需要提取proto信息, 例如: 所有的枚举,消息等信息, 字段名称和导出号. 自己编写词法解析器来做是费力不讨好的. 官方推荐的方法是使用protoc外挂插件来实现.</p> <p>protoc的插件设计比较独特, 不使用动态链接库或者java的jar包导入方式, 而是直接使用了命令行来交换数据.查看protobuf源码我们可以发现这样一个文件:</p> <p>protobuf-2.5.0\src\google\protobuf\descriptor.proto</p> <p>这个文件描述了一个proto文件的格式, 消息组成及枚举等完整信息. 这是一种自我描述的方法. </p> <p>在找到这样一个文件</p> <p>protobuf-2.5.0\src\google\protobuf\compiler\plugin.proto</p> <p>这样一个文件描述: 插件如何与protoc进行交互的协议</p> <p>protoc编译器在给定指定proto文件及搜索路径后, 将各种信息填充为descriptor.proto描述的结构后通过CodeGeneratorRequest消息系列化为二进制流后输出到命令行. 插件只用捕获protoc命令行输出的二进制流, 序列化化回CodeGeneratorRequest即可获得解析后的proto文件内容</p> <p>这里需要注意的是: 插件可执行文件很有讲究, 必须为protoc-gen-$NAME,&nbsp; 而且输出文件名参数必须为--${NAME}_out</p> <p>看一个栗子:</p> <p>protoc.exe foo.proto --plugin=protoc-gen-go=..\tools\protoc-gen-go.exe --go_out foo.go --proto_path "."</p> <p>这个栗子里: $NAME=go</p> <p>protoc将foo.proto文件(搜索路径为当前路径)的内容通过命令行输出给位于..\tools\的插件protoc-gen-go.exe,&nbsp; 输出文件名字为 foo.go</p> <p><strong>descriptor.proto信息挖掘</strong></p> <p>我们注意到在descriptor.proto文件中包含有这样的一个message: SourceCodeInfo, 这个消息体里有如下字段</p> <p>optional string leading_comments = 3;<br>&nbsp;&nbsp;&nbsp; optional string trailing_comments = 4;  <p>这两个字段对于我们获取proto文件的meta信息尤为重要, 所谓的meta信息, 理解理解为C#语言中的attribute  <p>这个attribute功能可以为一个字段, 一个消息扩充一些描述. 比如: 当一个字段通过反射显示在gui上时, gui需要获取这个字段的中文描述  <p>那么只需要如下编写  <p>optional int32 somevalue = 1 //@ desc=”中文描述”  <p>位于字段尾部的描述, 会被填充到SourceCodeInfo的 trailing_comments中, 而位于字段上方的字段, 会被填充到leading_comments中  <p>&nbsp; <p>SourceCodeInfo 并没有直接挂载在message或者字段的附近, 而是通过其下的path字段来描述与字段的关系, 这是个极为麻烦的设计.  <p>其原理如下:  <p>假设我有如下一个message  <p>message foo  <p>{  <p>&nbsp;&nbsp;&nbsp;&nbsp; optional int32 v = 1;&nbsp; // comments  <p>}  <p>要获取v后的注释, 对应的path为 4, 0, 2, 0  <p>4 表示descriptor中message_type所在的序号,由于message_type对应的类型DescriptorProto是一个数组, 所以0表示foo是在FileDescriptorProto的message_type数组类型的索引为0;  <p>如此类推: 2, 0 表示 v在DescriptorProto结构体的field成员序号为2的数组元素的索引为0  <p>&nbsp; <p><strong>如果需要更多的参考, 可以获取</strong><a title="https://github.com/golang/protobuf" href="https://github.com/golang/protobuf"><strong>https://github.com/golang/protobuf</strong></a><strong> </strong> <p>github.com\golang\protobuf\protoc-gen-go工程内有详细代码解析  <img src ="http://www.cppblog.com/sunicdavy/aggbug/209894.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2015-03-01 13:49 <a href="http://www.cppblog.com/sunicdavy/archive/2015/03/01/209894.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>探访lua5.2新特性及package机制模拟</title><link>http://www.cppblog.com/sunicdavy/archive/2013/12/10/204696.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Tue, 10 Dec 2013 08:29:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2013/12/10/204696.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/204696.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2013/12/10/204696.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/204696.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/204696.html</trackback:ping><description><![CDATA[<p>项目客户端脚本全面升级lua5.2 这是自06年后最大的一次主干更新, 带来的机制, 函数变化也是非常不错的</p> <p>1. 去掉了全局性质的setfenv/getfenv系列函数, 语言层面提供_ENV语法糖, 这东西跟:操作符一样, 只存在于编译期.</p> <p>官方建议自己实现module/require/package机制, 毕竟原生这套机制实现太弱智了..</p> <p>2. 提供了无符号访问函数</p> <p>3. 更多的lua api变化. 如果想兼容lua5.1的写法, 可以参考<a href="http://vinniefalco.com/LuaBridge/Manual.html">luabridge</a>内LuaHelpers.h的实现</p> <p>以下是本人使用lua5.2实现的一套package机制, 供大家参考</p> <div class="csharpcode"><pre class="alt">package = {}</pre><pre>&nbsp;</pre><pre class="alt">-- 读取标记</pre><pre>package.loaded = {}</pre><pre class="alt">&nbsp;</pre><pre>-- 搜索路径数组</pre><pre class="alt">package.path = {}</pre><pre>&nbsp;</pre><pre class="alt">package.access =</pre><pre>{</pre><pre class="alt">    [<span class="str">"string"</span>] = <span class="kwrd">string</span>,</pre><pre>    [<span class="str">"print"</span>] = print,</pre><pre class="alt">    [<span class="str">"table"</span>] = table,</pre><pre>    [<span class="str">"assert"</span>] = assert,</pre><pre class="alt">    [<span class="str">"error"</span>] = error,</pre><pre>    [<span class="str">"pairs"</span>] = pairs,</pre><pre class="alt">    [<span class="str">"ipairs"</span>] = ipairs,</pre><pre>    [<span class="str">"tonumber"</span>] = tonumber,</pre><pre class="alt">    [<span class="str">"tostring"</span>] = tostring,</pre><pre>    [<span class="str">"type"</span>] = type,</pre><pre class="alt">    [<span class="str">"math"</span>] = math,</pre><pre>}</pre><pre class="alt">&nbsp;</pre><pre>local function getreadablepath( name, pathlist )</pre><pre class="alt">    <span class="kwrd">for</span> _, path <span class="kwrd">in</span> ipairs(pathlist) <span class="kwrd">do</span></pre><pre>        </pre><pre class="alt">        local fullpath = path .. <span class="str">"/"</span> .. name .. <span class="str">".lua"</span></pre><pre>        local f = io.open( fullpath )</pre><pre class="alt">        <span class="kwrd">if</span> f then</pre><pre>            f:close()</pre><pre class="alt">            <span class="kwrd">return</span> fullpath</pre><pre>        end</pre><pre class="alt">    end</pre><pre>    </pre><pre class="alt">    <span class="kwrd">return</span> nil</pre><pre>    </pre><pre class="alt">end</pre><pre>&nbsp;</pre><pre class="alt">&nbsp;</pre><pre>function package.import( name )</pre><pre class="alt">&nbsp;</pre><pre>    -- 已经读取的直接返回</pre><pre class="alt">    local existedenv = package.loaded[name]</pre><pre>    <span class="kwrd">if</span> existedenv then</pre><pre class="alt">        <span class="kwrd">return</span> existedenv</pre><pre>    end</pre><pre class="alt">    </pre><pre>    local access = package.access</pre><pre class="alt">    </pre><pre>    -- 设置访问控制权限</pre><pre class="alt">    local meta = </pre><pre>    {</pre><pre class="alt">        __index = function( tab, key )</pre><pre>            </pre><pre class="alt">            -- 优先取包的空间</pre><pre>            local v = rawget( tab, key )</pre><pre class="alt">            </pre><pre>            <span class="kwrd">if</span> v then</pre><pre class="alt">                <span class="kwrd">return</span> v</pre><pre>            end</pre><pre class="alt">            </pre><pre>            -- 找不到时,从可访问的权限表中查找</pre><pre class="alt">            <span class="kwrd">return</span> access[key]             </pre><pre>            </pre><pre class="alt">        end,</pre><pre>    }</pre><pre class="alt">    </pre><pre>    -- 初始化一个包的全局环境, 并设置访问方法</pre><pre class="alt">    local env = setmetatable( {} , meta )</pre><pre>    </pre><pre class="alt">    --</pre><pre>    local readablepath = getreadablepath( name, package.path )</pre><pre class="alt">    </pre><pre>    <span class="kwrd">if</span> not readablepath then</pre><pre class="alt">        error(<span class="kwrd">string</span>.format(<span class="str">"package '%s' not found \n%s"</span>, name, table.concat( package.path, <span class="str">"\n"</span> ) ) )</pre><pre>    end</pre><pre class="alt">&nbsp;</pre><pre>    local func = loadfile( readablepath, <span class="str">"bt"</span>,  env )</pre><pre class="alt">    </pre><pre>    <span class="kwrd">if</span> type(func) ~= <span class="str">"function"</span> then</pre><pre class="alt">        <span class="kwrd">return</span> nil</pre><pre>    end</pre><pre class="alt">    </pre><pre>    -- 设置标记</pre><pre class="alt">    package.loaded[name] = env</pre><pre>    </pre><pre class="alt">    -- 执行全局空间</pre><pre>    func( )</pre><pre class="alt">    </pre><pre>    <span class="kwrd">return</span> env</pre><pre class="alt">end</pre><pre>&nbsp;</pre><pre class="alt">package.path = {<span class="str">"E:/Download/t"</span>}</pre><pre>local m = package.import <span class="str">"m"</span></pre><pre class="alt">&nbsp;</pre><pre>m.foo()</pre><pre>以下是m模块(m.lua)的内容</pre><pre>&nbsp;</pre>
<div class="csharpcode"><pre class="alt">&nbsp;</pre><pre>&nbsp;</pre><pre class="alt">function foo( )</pre><pre>    print(<span class="str">"转载注明: 战魂小筑 http://www.cppblog.com/sunicdavy"</span>, io )    </pre><pre class="alt">end</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>
</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>测试结果中, io打印出nil, 显示权限已经被控制住</p>
<p>本package设计比原生package更灵活, 更强大</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/204696.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-10 16:29 <a href="http://www.cppblog.com/sunicdavy/archive/2013/12/10/204696.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>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>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>Lua实现事件派发器</title><link>http://www.cppblog.com/sunicdavy/archive/2013/04/24/199692.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Wed, 24 Apr 2013 07:19:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2013/04/24/199692.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/199692.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2013/04/24/199692.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/199692.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/199692.html</trackback:ping><description><![CDATA[<p>为了降低模块间的耦合, 很多系统使用事件派发机制, 接收方无需知道派发者是谁.在Qt中,这个系统被称作Slot&amp;Signal, 需要配合moc代码生成机制, 但是系统本身是线程安全的.</p> <p>这里我们讨论的是lua的事件派发机制, 我将此写成lua模块, 方便配合cocos2dx进行逻辑处理</p> <p>&nbsp;</p> <div class="csharpcode"><pre class="alt"><span class="kwrd">local</span> Global = _G</pre><pre><span class="kwrd">local</span> package = _G.package</pre><pre class="alt"><span class="kwrd">local</span> setmetatable = _G.setmetatable</pre><pre><span class="kwrd">local</span> assert = _G.assert</pre><pre class="alt"><span class="kwrd">local</span> table = _G.table</pre><pre><span class="kwrd">local</span> pairs = _G.pairs</pre><pre class="alt"><span class="kwrd">local</span> ipairs = _G.ipairs</pre><pre>&nbsp;</pre><pre class="alt">&nbsp;</pre><pre>module <span class="str">"Core.EventDispatcher"</span></pre><pre class="alt">&nbsp;</pre><pre>--[[</pre><pre class="alt">数据层次</pre><pre>&nbsp;</pre><pre class="alt">[<span class="str">"EventName1"</span>] =</pre><pre>{</pre><pre class="alt">    [<span class="str">"_StaticFunc"</span>] = { Func1, Func2 },</pre><pre>    </pre><pre class="alt">    [Object1] = { Func1, Func2 },</pre><pre>    [Object2] = { Func1, Func2 },</pre><pre class="alt">},</pre><pre>&nbsp;</pre><pre class="alt">[<span class="str">"EventName2"</span>] =</pre><pre>{</pre><pre class="alt">    ...</pre><pre>}</pre><pre class="alt">&nbsp;</pre><pre>]]</pre><pre class="alt">&nbsp;</pre><pre>-- 默认调用函数</pre><pre class="alt"><span class="kwrd">local</span> <span class="kwrd">function</span> PreInvoke( EventName, Func, Object, UserData, ... )</pre><pre>    </pre><pre class="alt">    <span class="kwrd">if</span> Object then</pre><pre>        Func( Object, EventName, ... )</pre><pre class="alt">    <span class="kwrd">else</span></pre><pre>        Func( EventName, ... )</pre><pre class="alt">    <span class="kwrd">end</span></pre><pre>&nbsp;</pre><pre class="alt"><span class="kwrd">end</span></pre><pre>&nbsp;</pre><pre class="alt"><span class="kwrd">function</span> New( )    </pre><pre>    </pre><pre class="alt">    <span class="kwrd">local</span> NewObj = setmetatable( {}, { __index = package.loaded[<span class="str">"Core.EventDispatcher"</span>] } )</pre><pre>    </pre><pre class="alt">    -- 对象成员初始化</pre><pre>    NewObj.mPreInvokeFunc = PreInvoke</pre><pre class="alt">    NewObj.mEventTable = {}</pre><pre>    </pre><pre class="alt">    <span class="kwrd">return</span> NewObj</pre><pre><span class="kwrd">end</span></pre><pre class="alt">&nbsp;</pre><pre>-- 添加</pre><pre class="alt"><span class="kwrd">function</span> Add( Self, EventName, Func, Object, UserData )</pre><pre>&nbsp;</pre><pre class="alt">    assert( Func )</pre><pre>&nbsp;</pre><pre class="alt">    Self.mEventTable[ EventName ] = Self.mEventTable[ EventName ] or {}</pre><pre>    </pre><pre class="alt">    <span class="kwrd">local</span> Event = Self.mEventTable[ EventName ]</pre><pre>    </pre><pre class="alt">    <span class="kwrd">if</span> not Object then</pre><pre>        Object = <span class="str">"_StaticFunc"</span></pre><pre class="alt">    <span class="kwrd">end</span></pre><pre>    </pre><pre class="alt">    Event[Object] = Event[Object] or {}</pre><pre>    <span class="kwrd">local</span> ObjectEvent = Event[Object]</pre><pre class="alt">&nbsp;</pre><pre>    ObjectEvent[Func] = UserData or true</pre><pre class="alt">    </pre><pre><span class="kwrd">end</span></pre><pre class="alt">&nbsp;</pre><pre>-- 设置调用前回调</pre><pre class="alt"><span class="kwrd">function</span> SetDispatchHook( Self, HookFunc )</pre><pre>    </pre><pre class="alt">    Self.mPreInvokeFunc = HookFunc</pre><pre><span class="kwrd">end</span></pre><pre class="alt">&nbsp;</pre><pre>&nbsp;</pre><pre class="alt">-- 派发</pre><pre><span class="kwrd">function</span> Dispatch( Self, EventName, ... )</pre><pre class="alt">&nbsp;</pre><pre>    assert( EventName )</pre><pre class="alt">    </pre><pre>    <span class="kwrd">local</span> Event = Self.mEventTable[ EventName ]</pre><pre class="alt">    </pre><pre>    <span class="kwrd">for</span> Object,ObjectFunc <span class="kwrd">in</span> pairs( Event ) do</pre><pre class="alt">        </pre><pre>        <span class="kwrd">if</span> Object == <span class="str">"_StaticFunc"</span> then</pre><pre class="alt">                </pre><pre>            <span class="kwrd">for</span> Func, UserData <span class="kwrd">in</span> pairs( ObjectFunc ) do</pre><pre class="alt">                Self.mPreInvokeFunc( EventName, Func, nil, UserData, ... )    </pre><pre>            <span class="kwrd">end</span></pre><pre class="alt">            </pre><pre>        <span class="kwrd">else</span></pre><pre class="alt">        </pre><pre>            <span class="kwrd">for</span> Func, UserData <span class="kwrd">in</span> pairs( ObjectFunc ) do</pre><pre class="alt">                Self.mPreInvokeFunc( EventName, Func, Object, UserData, ... )</pre><pre>            <span class="kwrd">end</span></pre><pre class="alt">        </pre><pre>        <span class="kwrd">end</span></pre><pre class="alt">&nbsp;</pre><pre>    <span class="kwrd">end</span></pre><pre class="alt">&nbsp;</pre><pre><span class="kwrd">end</span></pre><pre class="alt">&nbsp;</pre><pre>-- 回调是否存在</pre><pre class="alt"><span class="kwrd">function</span> Exist( Self, EventName )</pre><pre>&nbsp;</pre><pre class="alt">    assert( EventName )</pre><pre>    </pre><pre class="alt">    <span class="kwrd">local</span> Event = Self.mEventTable[ EventName ]</pre><pre>    </pre><pre class="alt">    <span class="kwrd">if</span> not Event then</pre><pre>        <span class="kwrd">return</span> false</pre><pre class="alt">    <span class="kwrd">end</span></pre><pre>    </pre><pre class="alt">    -- 需要遍历下map, 可能有事件名存在, 但是没有任何回调的</pre><pre>    <span class="kwrd">for</span> Object,ObjectFunc <span class="kwrd">in</span> pairs( Event ) do</pre><pre class="alt">    </pre><pre>        <span class="kwrd">for</span> Func, _ <span class="kwrd">in</span> pairs( ObjectFunc ) do</pre><pre class="alt">            -- 居然有一个</pre><pre>            <span class="kwrd">return</span> true</pre><pre class="alt">        <span class="kwrd">end</span></pre><pre>    </pre><pre class="alt">    <span class="kwrd">end</span></pre><pre>    </pre><pre class="alt">    </pre><pre>    <span class="kwrd">return</span> false</pre><pre class="alt">    </pre><pre><span class="kwrd">end</span></pre><pre class="alt">&nbsp;</pre><pre>-- 清除</pre><pre class="alt"><span class="kwrd">function</span> Remove( Self, EventName, Func, Object )</pre><pre>    </pre><pre class="alt">    assert( Func )</pre><pre>    </pre><pre class="alt">    <span class="kwrd">local</span> Event = Self.mEventTable[ EventName ]</pre><pre>    </pre><pre class="alt">    <span class="kwrd">if</span> not Event then</pre><pre>        <span class="kwrd">return</span></pre><pre class="alt">    <span class="kwrd">end</span></pre><pre>    </pre><pre class="alt">    <span class="kwrd">if</span> not Object then</pre><pre>        Object = <span class="str">"_StaticFunc"</span></pre><pre class="alt">    <span class="kwrd">end</span></pre><pre>    </pre><pre class="alt">    </pre><pre>    <span class="kwrd">local</span> ObjectEvent = Event[Object]</pre><pre class="alt">    </pre><pre>    <span class="kwrd">if</span> not ObjectEvent then</pre><pre class="alt">        <span class="kwrd">return</span></pre><pre>    <span class="kwrd">end</span></pre><pre class="alt">    </pre><pre>    ObjectEvent[Func] = nil</pre><pre class="alt">&nbsp;</pre><pre>        </pre><pre class="alt"><span class="kwrd">end</span></pre><pre>&nbsp;</pre><pre class="alt">-- 清除对象的所有回调</pre><pre><span class="kwrd">function</span> RemoveObjectAllFunc( Self, EventName, Object )</pre><pre class="alt">&nbsp;</pre><pre>    assert( Object )</pre><pre class="alt">    </pre><pre>    <span class="kwrd">local</span> Event = Self.mEventTable[ EventName ]</pre><pre class="alt">    </pre><pre>    <span class="kwrd">if</span> not Event then</pre><pre class="alt">        <span class="kwrd">return</span></pre><pre>    <span class="kwrd">end</span></pre><pre class="alt">    </pre><pre>    Event[Object] = nil</pre><pre class="alt">&nbsp;</pre><pre><span class="kwrd">end</span></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>这里注意下, 我是将EventDispatcher.lua放置在Core目录下, 因此需要使用require “Core.EventDispatcher”进行调用</p>
<p>使用用例</p>
<p>&nbsp;</p>
<div class="csharpcode"><pre class="alt">    <span class="kwrd">local</span> EventDispatcher = require <span class="str">'Core.EventDispatcher'</span></pre><pre>&nbsp;</pre><pre class="alt">    <span class="kwrd">local</span> E = EventDispatcher.New()</pre><pre>&nbsp;</pre><pre class="alt">&nbsp;</pre><pre>    E:Add( <span class="str">"a"</span>, <span class="kwrd">function</span>( a, b )   print( a, b ) <span class="kwrd">end</span> )</pre><pre class="alt">&nbsp;</pre><pre>    <span class="kwrd">local</span> Func = <span class="kwrd">function</span>( a )   print( a ) <span class="kwrd">end</span> </pre><pre class="alt">    E:Add( <span class="str">"a"</span>, Func )</pre><pre>&nbsp;</pre><pre class="alt">&nbsp;</pre><pre>    E:Dispatch(<span class="str">"a"</span>, 1, 2 )</pre><pre class="alt">    print( E:Exist(<span class="str">"a"</span>), E:Exist(<span class="str">"b"</span>))</pre><pre>&nbsp;</pre><pre class="alt">    E:Remove(<span class="str">"a"</span>, Func )</pre><pre>&nbsp;</pre><pre class="alt">    E:Dispatch(<span class="str">"a"</span>, 1, 2 )</pre><pre>    print( E:Exist(<span class="str">"a"</span>), E:Exist(<span class="str">"b"</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><img src ="http://www.cppblog.com/sunicdavy/aggbug/199692.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:19 <a href="http://www.cppblog.com/sunicdavy/archive/2013/04/24/199692.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Excel中VBA转换文件编码到UTF-8</title><link>http://www.cppblog.com/sunicdavy/archive/2012/09/13/190553.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Thu, 13 Sep 2012 11:43:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/09/13/190553.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/190553.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/09/13/190553.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/190553.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/190553.html</trackback:ping><description><![CDATA[<p>网上找了很多, 真正好用的代码不多, 自己研究了下,写下例子备份</p> <p>&nbsp;</p> <div class="csharpcode"><pre class="alt"><span class="kwrd">Private</span> <span class="kwrd">Sub</span> ConvFile(InputFile <span class="kwrd">As</span> <span class="kwrd">String</span>, OutputFile <span class="kwrd">As</span> <span class="kwrd">String</span>)</pre><pre>&nbsp;</pre><pre class="alt">    <span class="kwrd">Dim</span> ReadStream <span class="kwrd">As</span> <span class="kwrd">Object</span></pre><pre>    <span class="kwrd">Set</span> ReadStream = CreateObject(<span class="str">"ADODB.Stream"</span>)</pre><pre class="alt">    </pre><pre>    <span class="kwrd">Dim</span> FileContent <span class="kwrd">As</span> <span class="kwrd">String</span></pre><pre class="alt">    </pre><pre>    <span class="kwrd">With</span> ReadStream</pre><pre class="alt">        .Type = 2               <span class="rem">'adTypeText</span></pre><pre>        .Charset = <span class="str">"UNICODE"</span></pre><pre class="alt">        .Open</pre><pre>        .LoadFromFile InputFile</pre><pre class="alt">        FileContent = .ReadText</pre><pre>        .Close</pre><pre class="alt">        </pre><pre>    <span class="kwrd">End</span> <span class="kwrd">With</span></pre><pre class="alt">    </pre><pre>    <span class="kwrd">Set</span> ReadStream = <span class="kwrd">Nothing</span></pre><pre class="alt">    </pre><pre>    </pre><pre class="alt">    </pre><pre>    <span class="kwrd">Dim</span> WriteStream <span class="kwrd">As</span> <span class="kwrd">Object</span></pre><pre class="alt">    <span class="kwrd">Set</span> WriteStream = CreateObject(<span class="str">"ADODB.Stream"</span>)</pre><pre>       </pre><pre class="alt">    </pre><pre>    <span class="kwrd">With</span> WriteStream</pre><pre class="alt">        .Type = 2               <span class="rem">'adTypeText</span></pre><pre>        .Charset = <span class="str">"UTF-8"</span></pre><pre class="alt">        .Open</pre><pre>        .WriteText FileContent</pre><pre class="alt">        .SaveToFile OutputFile, 2  <span class="rem">'adSaveCreateOverWrite</span></pre><pre>        </pre><pre class="alt">        .Flush</pre><pre>        .Close</pre><pre class="alt">        </pre><pre>    <span class="kwrd">End</span> <span class="kwrd">With</span></pre><pre class="alt">    </pre><pre>    <span class="kwrd">Set</span> WriteStream = <span class="kwrd">Nothing</span></pre><pre class="alt">&nbsp;</pre><pre>    </pre><pre class="alt"><span class="kwrd">End</span> Sub</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>上半截是读取文件, 下半截是写入文件, 需要转换不同格式, 请自行更换</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/190553.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-09-13 19:43 <a href="http://www.cppblog.com/sunicdavy/archive/2012/09/13/190553.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux服务自动安装卸载部署脚本</title><link>http://www.cppblog.com/sunicdavy/archive/2012/04/12/171026.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Thu, 12 Apr 2012 01:33:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/04/12/171026.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/171026.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/04/12/171026.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/171026.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/171026.html</trackback:ping><description><![CDATA[<pre class="csharpcode"><span class="rem">#!/bin/bash</span>
<span class="rem"># chkconfig: 3 3 1</span>
<span class="rem"># description: svclauncher</span></pre><pre class="csharpcode">ServicePath=/usr/<span class="kwrd">local</span>/bin

ServiceList=(
<span class="str">"wkcenterd --toc /home/davy/dev/kaze/Config/CenterService.toc --logfile /tmp/centerd.log"</span>
<span class="str">"wkagentd --toc /home/davy/dev/kaze/Config/AgentService.toc --logfile /tmp/agentd.log"</span>
)

StartAll()
{
    <span class="kwrd">for</span>((i = 0;i&lt;${<span class="rem">#ServiceList[*]};i=i+1))</span>
    do

     echo <span class="str">"start:"</span> $ServicePath/${ServiceList[i]}
     $ServicePath/${ServiceList[i]} &gt; /dev/null &amp;

    done
}

StopAll()
{
    <span class="kwrd">for</span>((i = 0;i&lt;${<span class="rem">#ServiceList[*]};i=i+1))</span>
    do

     echo <span class="str">"stop:"</span> $ServicePath/${ServiceList[i]}
     svcname=`echo ${ServiceList[i]} | awk <span class="str">'{print $1}'</span>`
     killall $svcname &gt; /dev/null

    done
}

RestartAll()
{
    StopAll
    StartAll
}


InstallService()
{
    svcname=`basename $0`
    chmod +x $svcname
    cp $svcname /etc/init.d
    ln /etc/init.d/$svcname /etc/rc3.d/S03$svcname
    ln /etc/init.d/$svcname /etc/rc0.d/K03$svcname
    chkconfig --add $svcname
    chkconfig $svcname on
    chkconfig --list | grep $svcname
}

UninstallService()
{
    svcname=`basename $0`
    chkconfig --del $svcname
    rm -f /etc/init.d/$svcname
    rm -f /etc/rc3.d/S03$svcname
    rm -f /etc/rc3.d/K03$svcname
}



case <span class="str">"$1"</span> <span class="kwrd">in</span>
    start)
    StartAll
    ;;
    stop)
    StopAll
    ;;
    restart)
    RestartAll
    ;;
    install)
    InstallService
    ;;
    uninstall)
    UninstallService
    ;;
    *)
           echo <span class="str">"Usage: service $EXEC {install|start|stop|restart|uninst}"</span>
       exit 1
esac
 
exit $? </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><img src ="http://www.cppblog.com/sunicdavy/aggbug/171026.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-12 09:33 <a href="http://www.cppblog.com/sunicdavy/archive/2012/04/12/171026.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><item><title>为lua构建沙盒(SandBox)环境</title><link>http://www.cppblog.com/sunicdavy/archive/2012/03/02/166948.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Fri, 02 Mar 2012 01:40:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/03/02/166948.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/166948.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/03/02/166948.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/166948.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/166948.html</trackback:ping><description><![CDATA[<p>我们有时需要限制lua代码的运行环境,或者是让使用者不能访问到lua的一些全局函数.lua语言本身没有类似于C++, C#, Java那样的成员访问控制. 但lua提供了setfenv函数可以很灵活的处理各类权限问题</p> <p>废话不多说, 看代码</p> <div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>-- 创建沙盒</pre><pre><span class="lnum">   2:  </span><span class="kwrd">function</span> SpawnSandBox( )</pre><pre class="alt"><span class="lnum">   3:  </span>&nbsp;</pre><pre><span class="lnum">   4:  </span>    <span class="kwrd">local</span> SandBoxGlobals = {}</pre><pre class="alt"><span class="lnum">   5:  </span>    </pre><pre><span class="lnum">   6:  </span>    -- 基础函数添加</pre><pre class="alt"><span class="lnum">   7:  </span>    SandBoxGlobals.print             = print</pre><pre><span class="lnum">   8:  </span>    SandBoxGlobals.table             = table</pre><pre class="alt"><span class="lnum">   9:  </span>    SandBoxGlobals.string             = string     </pre><pre><span class="lnum">  10:  </span>    SandBoxGlobals.math               = math </pre><pre class="alt"><span class="lnum">  11:  </span>    SandBoxGlobals.assert             = assert </pre><pre><span class="lnum">  12:  </span>    SandBoxGlobals.getmetatable    = getmetatable </pre><pre class="alt"><span class="lnum">  13:  </span>    SandBoxGlobals.ipairs             = ipairs </pre><pre><span class="lnum">  14:  </span>    SandBoxGlobals.pairs             = pairs </pre><pre class="alt"><span class="lnum">  15:  </span>    SandBoxGlobals.pcall             = pcall </pre><pre><span class="lnum">  16:  </span>    SandBoxGlobals.setmetatable    = setmetatable </pre><pre class="alt"><span class="lnum">  17:  </span>    SandBoxGlobals.tostring        = tostring </pre><pre><span class="lnum">  18:  </span>    SandBoxGlobals.tonumber        = tonumber </pre><pre class="alt"><span class="lnum">  19:  </span>    SandBoxGlobals.type            = type </pre><pre><span class="lnum">  20:  </span>    SandBoxGlobals.unpack             = unpack </pre><pre class="alt"><span class="lnum">  21:  </span>    SandBoxGlobals.collectgarbage     = collectgarbage</pre><pre><span class="lnum">  22:  </span>    SandBoxGlobals._G                = SandBoxGlobals</pre><pre class="alt"><span class="lnum">  23:  </span>    </pre><pre><span class="lnum">  24:  </span>    <span class="kwrd">return</span> SandBoxGlobals</pre><pre class="alt"><span class="lnum">  25:  </span><span class="kwrd">end</span></pre><pre><span class="lnum">  26:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">  27:  </span>-- 在沙盒内执行脚本, 出错时返回错误, nil表示正确</pre><pre><span class="lnum">  28:  </span><span class="kwrd">function</span> ExecuteInSandBox( SandBox, Script )</pre><pre class="alt"><span class="lnum">  29:  </span>    </pre><pre><span class="lnum">  30:  </span>    <span class="kwrd">local</span> ScriptFunc, CompileError = loadstring( Script )</pre><pre class="alt"><span class="lnum">  31:  </span>    </pre><pre><span class="lnum">  32:  </span>    <span class="kwrd">if</span> CompileError then</pre><pre class="alt"><span class="lnum">  33:  </span>        <span class="kwrd">return</span> CompileError</pre><pre><span class="lnum">  34:  </span>    <span class="kwrd">end</span></pre><pre class="alt"><span class="lnum">  35:  </span>    </pre><pre><span class="lnum">  36:  </span>    setfenv( ScriptFunc, SandBox )</pre><pre class="alt"><span class="lnum">  37:  </span>    </pre><pre><span class="lnum">  38:  </span>    <span class="kwrd">local</span> Result, RuntimeError = pcall( ScriptFunc )</pre><pre class="alt"><span class="lnum">  39:  </span>    <span class="kwrd">if</span> RuntimeError then</pre><pre><span class="lnum">  40:  </span>        <span class="kwrd">return</span> RuntimeError</pre><pre class="alt"><span class="lnum">  41:  </span>    <span class="kwrd">end</span></pre><pre><span class="lnum">  42:  </span>    </pre><pre class="alt"><span class="lnum">  43:  </span>    <span class="kwrd">return</span> nil</pre><pre><span class="lnum">  44:  </span><span class="kwrd">end</span></pre><pre class="alt"><span class="lnum">  45:  </span>&nbsp;</pre><pre><span class="lnum">  46:  </span><span class="kwrd">function</span> ProtectedFunction( )</pre><pre class="alt"><span class="lnum">  47:  </span>    print(<span class="str">"protected func"</span>)</pre><pre><span class="lnum">  48:  </span><span class="kwrd">end</span></pre><pre class="alt"><span class="lnum">  49:  </span>&nbsp;</pre><pre><span class="lnum">  50:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">  51:  </span><span class="kwrd">local</span> SandBox = SpawnSandBox( )</pre><pre><span class="lnum">  52:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">  53:  </span>&nbsp;</pre><pre><span class="lnum">  54:  </span>print ( <span class="str">"Response="</span>, ExecuteInSandBox( SandBox, <span class="str">"table.foreach( _G, print )"</span> ) )</pre><pre class="alt"><span class="lnum">  55:  </span>&nbsp;</pre><pre><span class="lnum">  56:  </span>print ( <span class="str">"Response="</span>, ExecuteInSandBox( SandBox, <span class="str">"ProtectedFunction()"</span> ) )</pre><pre class="alt"><span class="lnum">  57:  </span>&nbsp;</pre><pre><span class="lnum">  58:  </span>SandBox.ProtectedFunction = ProtectedFunction</pre><pre class="alt"><span class="lnum">  59:  </span>&nbsp;</pre><pre><span class="lnum">  60:  </span>print ( <span class="str">"Response="</span>, ExecuteInSandBox( SandBox, <span class="str">"ProtectedFunction()"</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>

<p>&nbsp;</p>
<p>54行执行结果是</p>
<p>&nbsp;</p>
<div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>_G    table: 00421258</pre></div>
<div class="csharpcode"><pre><span class="lnum">   2:  </span>string    table: 00421050</pre></div>
<div class="csharpcode"><pre class="alt"><span class="lnum">   3:  </span>pairs    <span class="kwrd">function</span>: 00567F58</pre></div>
<div class="csharpcode"><pre><span class="lnum">   4:  </span>collectgarbage    <span class="kwrd">function</span>: 005675F0</pre></div>
<div class="csharpcode"><pre class="alt"><span class="lnum">   5:  </span>unpack    <span class="kwrd">function</span>: 004217E8</pre></div>
<div class="csharpcode"><pre><span class="lnum">   6:  </span>assert    <span class="kwrd">function</span>: 005675B0</pre></div>
<div class="csharpcode"><pre class="alt"><span class="lnum">   7:  </span>print    <span class="kwrd">function</span>: 00567830</pre></div>
<div class="csharpcode"><pre><span class="lnum">   8:  </span>ipairs    <span class="kwrd">function</span>: 00567F28</pre></div>
<div class="csharpcode"><pre class="alt"><span class="lnum">   9:  </span>type    <span class="kwrd">function</span>: 004217A8</pre></div>
<div class="csharpcode"><pre><span class="lnum">  10:  </span>tonumber    <span class="kwrd">function</span>: 00421768</pre></div>
<div class="csharpcode"><pre class="alt"><span class="lnum">  11:  </span>tostring    <span class="kwrd">function</span>: 00421788</pre></div>
<div class="csharpcode"><pre><span class="lnum">  12:  </span>table    table: 00420DA8</pre></div>
<div class="csharpcode"><pre class="alt"><span class="lnum">  13:  </span>math    table: 004210C8</pre></div>
<div class="csharpcode"><pre><span class="lnum">  14:  </span>setmetatable    <span class="kwrd">function</span>: 00421748</pre></div>
<div class="csharpcode"><pre class="alt"><span class="lnum">  15:  </span>getmetatable    <span class="kwrd">function</span>: 00567710</pre></div>
<div class="csharpcode"><pre><span class="lnum">  16:  </span>pcall    <span class="kwrd">function</span>: 005677F0</pre></div>
<div class="csharpcode"><pre class="alt"><span class="lnum">  17:  </span>Response=    nil</pre></div>
<div class="csharpcode">&nbsp;</div>
<div class="csharpcode">54行由于没有注册这个全局函数, 因此无法访问</div>
<div class="csharpcode">Response=&nbsp;&nbsp;&nbsp; [string "ProtectedFunction()"]:1: attempt to call global 'ProtectedFunction' (a nil value)</div>
<div class="csharpcode">&nbsp;</div>
<div class="csharpcode">58行在全局环境中加上了这个函数,因此在60行访问正常</div>
<div class="csharpcode">protected func<br>Response=&nbsp;&nbsp;&nbsp; nil</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>

<div class="csharpcode">&nbsp;</div><img src ="http://www.cppblog.com/sunicdavy/aggbug/166948.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-02 09:40 <a href="http://www.cppblog.com/sunicdavy/archive/2012/03/02/166948.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux下将ldd打印的依赖列表拷贝到指定目录</title><link>http://www.cppblog.com/sunicdavy/archive/2012/02/29/166791.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Wed, 29 Feb 2012 08:05:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2012/02/29/166791.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/166791.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2012/02/29/166791.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/166791.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/166791.html</trackback:ping><description><![CDATA[<p>Linux下的ldd命令可以查看一个可执行文件/共享库/静态库的依赖, 但是想得到这些依赖文件, 必须手动去找,非常麻烦</p> <p>这里是一个Shell可以将依赖列表中的文件拷贝到指定目录</p><pre class="csharpcode">deplist=$( ldd $1 | awk <span class="str">'{if (match($3,"/")){ print $3}}'</span> )
cp $deplist $2</pre><pre class="csharpcode">代码解释: ldd导出列表, 这个列表打印出来很丑</pre>
<p>linux-gate.so.1 =&gt;&nbsp; (0x00ed2000)<br>&nbsp;&nbsp;&nbsp; liblog4cpp.so.4 =&gt; /usr/local/lib/liblog4cpp.so.4 (0x00657000)<br>&nbsp;&nbsp;&nbsp; libprotobuf.so.7 =&gt; /usr/local/lib/libprotobuf.so.7 (0x00360000)<br>&nbsp;&nbsp;&nbsp; libboost_filesystem.so.1.48.0 =&gt; /usr/local/lib/libboost_filesystem.so.1.48.0 (0x00a9a000)<br>&nbsp;&nbsp;&nbsp; libboost_program_options.so.1.48.0 =&gt; /usr/local/lib/libboost_program_options.so.1.48.0 (0x00110000)<br>&nbsp;&nbsp;&nbsp; libboost_system.so.1.48.0 =&gt; /usr/local/lib/libboost_system.so.1.48.0 (0x00a85000)<br>&nbsp;&nbsp;&nbsp; libboost_thread.so.1.48.0 =&gt; /usr/local/lib/libboost_thread.so.1.48.0 (0x00179000)<br>&nbsp;&nbsp;&nbsp; libunwind-x86.so.7 =&gt; /usr/lib/libunwind-x86.so.7 (0x00821000)<br>&nbsp;&nbsp;&nbsp; libluabindd.so.0.9.0 =&gt; /usr/local/lib/libluabindd.so.0.9.0 (0x00bb3000)<br>&nbsp;&nbsp;&nbsp; libmysqlpp.so.3 =&gt; /usr/local/lib/libmysqlpp.so.3 (0x00de5000)<br>&nbsp;&nbsp;&nbsp; libstdc++.so.6 =&gt; /usr/lib/i386-linux-gnu/libstdc++.so.6 (0x001a9000)<br>&nbsp;&nbsp;&nbsp; libm.so.6 =&gt; /lib/i386-linux-gnu/libm.so.6 (0x00782000)<br>&nbsp;&nbsp;&nbsp; libgcc_s.so.1 =&gt; /lib/i386-linux-gnu/libgcc_s.so.1 (0x00aea000)<br>&nbsp;&nbsp;&nbsp; libc.so.6 =&gt; /lib/i386-linux-gnu/libc.so.6 (0x00447000)<br>&nbsp;&nbsp;&nbsp; libpthread.so.0 =&gt; /lib/i386-linux-gnu/libpthread.so.0 (0x00abd000)<br>&nbsp;&nbsp;&nbsp; librt.so.1 =&gt; /lib/i386-linux-gnu/librt.so.1 (0x00193000)<br>&nbsp;&nbsp;&nbsp; libnsl.so.1 =&gt; /lib/i386-linux-gnu/libnsl.so.1 (0x00294000)<br>&nbsp;&nbsp;&nbsp; libunwind.so.7 =&gt; /usr/lib/libunwind.so.7 (0x002ab000)<br>&nbsp;&nbsp;&nbsp; libdl.so.2 =&gt; /lib/i386-linux-gnu/libdl.so.2 (0x00e8a000)<br>&nbsp;&nbsp;&nbsp; libmysqlclient_r.so.16 =&gt; /usr/lib/libmysqlclient_r.so.16 (0x0083b000)<br>&nbsp;&nbsp;&nbsp; /lib/ld-linux.so.2 (0x00608000)<br>&nbsp;&nbsp;&nbsp; libz.so.1 =&gt; /lib/i386-linux-gnu/libz.so.1 (0x002c0000)<br></p>
<p>&nbsp;</p>
<p><font size="3" face="Consolas">我们发现第一行的so没有对应的库地址, 因此我们使用awk的脚本功能,判断第三个参数,也就是=&gt;之后的路径必须包含/</font></p>
<p><font size="3" face="Consolas">之后将第一行的输出重定向到变量中, 再使用cp指令从列表拷贝到指定目录</font>
<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/166791.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-02-29 16:05 <a href="http://www.cppblog.com/sunicdavy/archive/2012/02/29/166791.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用批处理为protocbuffer的输出c++文件添加预编译头</title><link>http://www.cppblog.com/sunicdavy/archive/2011/11/02/159518.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Wed, 02 Nov 2011 09:32:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2011/11/02/159518.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/159518.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2011/11/02/159518.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/159518.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/159518.html</trackback:ping><description><![CDATA[<p>使用ProtocolBuffer的编译程序protoc可以将.proto生成*.pb.cc的C++代码文件. 但是在带有预编译头的工程里, 就经常需要手动添加类似stdafx.h的包含. 这里使用批处理来完成这一过程:</p> <p>BuildProtoCC.bat</p> <p>@echo off  <p>set protofile=%1%.proto<br>set output_cc=%1%.pb.cc  <p>"protoc.exe" %protofile% --cpp_out .<br>@echo 使用%protofile%生成%output_cc%  <p>if exist "pchheader.txt" goto 合并预编译头 else echo pchheader.txt NOT EXIST  <p>:合并预编译头<br>@echo 尝试删除以前的中间文件<br>del *.pched<br>@echo 合并编译头文件pchheader.txt到生成%output_cc%<br>copy pchheader.txt+"%output_cc%" "%output_cc%.pched" /y<br>@echo 等待protoc.exe结束<br>@ping -n 2 127.1&gt;nul<br>echo 清理文件<br>del "%output_cc%"<br>ren "%output_cc%.pched" "%output_cc%" <p>&nbsp; <p>这段批处理这样使用: <p>假设你有一个叫login.proto文件和批处理放在一起 <p>在同一目录再放置一个pchheader.txt文件,并在里面写入#include "stdafx.h” <p>调用一下批处理 <p>call BuildProtoCC.bat login <p>注意login不能带后缀 <p>将使用protoc.exe生成login.pb.cc和login.pb.h 然后使用批处理合并文件功能自动合并预编译头 <img src ="http://www.cppblog.com/sunicdavy/aggbug/159518.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2011-11-02 17:32 <a href="http://www.cppblog.com/sunicdavy/archive/2011/11/02/159518.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>protocolbuffer添加ActionScript3支持</title><link>http://www.cppblog.com/sunicdavy/archive/2011/08/10/152995.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Wed, 10 Aug 2011 14:00:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2011/08/10/152995.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/152995.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2011/08/10/152995.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/152995.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/152995.html</trackback:ping><description><![CDATA[<p>protocolbuffer默认支持java, python 和c++,其他的语言需要自己编写代码生成器他语言的代码.</p> <p>不过官网也提到过ActionScript3的支持,点击看<a href="http://code.google.com/p/protobuf-actionscript3/">这里</a></p> <p><a href="http://code.google.com/p/protobuf-actionscript3/">protobuf-actionscript3</a>包括ActionScript3的序列号及反序列化的as源码.以及protoc的as3代码生成器的C++代码</p> <p>另外, <a href="http://code.google.com/p/protobuf-actionscript3/">protobuf-actionscript3</a>还需要一个加密库<a href="http://code.google.com/p/as3crypto/">as3crypto</a>支持,需要一并下载</p> <p>当然, <a href="http://code.google.com/p/protobuf/">protobuf</a> 库也是最重要的.</p> <p>下面说明如何编译出支持as3的protoc代码生成器:</p> <p>&nbsp;</p> <p>1. 将protobuf-actionscript3库中compiler\as3目录拷贝到protobuf库的src\google\protobuf\compiler下.目录结构如下:</p> <p>as3\<br>&nbsp;&nbsp;&nbsp; cpp\<br>&nbsp;&nbsp;&nbsp; java\<br>&nbsp;&nbsp;&nbsp; python\<br>&nbsp;&nbsp;&nbsp; code_generator.cc<br>&nbsp;&nbsp;&nbsp; command_line_interface.cc</p> <p>...  <p>&nbsp;</p> <p>2.打开protobuf工程中的sln, 在libprotoc添加刚才添加的as3目录下的所有文件</p> <p>3. 在protoc工程的main.cc中添加</p><pre class="csharpcode">  google::protobuf::compiler::as3::As3Generator as3_generator;
  cli.RegisterGenerator(<span class="str">"--as3_out"</span>, &amp;as3_generator,
      <span class="str">"Generate ActionScript source file."</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>

<p>4. 打开as3_file.h</p>
<p>注释掉以下代码</p><pre class="csharpcode"><span class="kwrd">namespace</span> protobuf {
  <span class="kwrd">class</span> FileDescriptor;        <span class="rem">// descriptor.h</span>
  <span class="kwrd">namespace</span> io {
    <span class="kwrd">class</span> Printer;             <span class="rem">// printer.h</span>
  }
  <span class="kwrd">namespace</span> compiler {
    <span class="kwrd">class</span> OutputDirectory;     <span class="rem">// code_generator.h</span>
  }
}</pre>
<p>包含内添加</p><pre class="csharpcode">#include &lt;google/protobuf/stubs/common.h&gt;
#include &lt;google/protobuf/compiler/code_generator.h&gt;
#include &lt;google/protobuf/io/printer.h&gt;</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">5. 编译出protoc.exe</pre><pre class="csharpcode">6. 准备proto文件, 使用protoc.exe使用类似CPP生成的方式进行生成</pre><pre class="csharpcode">7. 将protobuf-actionscript里的as3-lib及下载好的加密的swc整合到自己的flash工程即可开始使用</pre><img src ="http://www.cppblog.com/sunicdavy/aggbug/152995.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2011-08-10 22:00 <a href="http://www.cppblog.com/sunicdavy/archive/2011/08/10/152995.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>小试Squirrel松鼠脚本的远程调试功能</title><link>http://www.cppblog.com/sunicdavy/archive/2011/05/14/146376.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sat, 14 May 2011 09:42:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2011/05/14/146376.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/146376.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2011/05/14/146376.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/146376.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/146376.html</trackback:ping><description><![CDATA[<p>等了大半年,<a href="http://www.squirrel-lang.org/">松鼠脚本</a>终于释出了<a href="http://code.google.com/p/squirrel/">3.0稳定版本</a></p> <p>松鼠脚本可以说是Lua的超级增强版,作者在Crysis项目使用Lua多年,深知Lua的优缺点.之后自己编写了松鼠脚本来解决诸如class,attribute,delegation,更强大的thread,exception等等功能. </p> <p>松鼠脚本本身对Windows开发人员极为照顾,第三方库可谓丰富,远程调试,代码加色及语法检查都可以直接在VS2008的IDE中进行.</p> <p>简单的远程调试功能需要以下步骤:</p> <p>1. 下载<a href="http://code.google.com/p/squirrel/downloads/detail?name=squirrel_3_0_stable.tar.gz">松鼠脚本3.0版本</a></p> <p>2. 在<a href="http://wiki.squirrel-lang.org/default.aspx/SquirrelWiki/SquirrelWiki.html">松鼠脚本Wiki</a>中下载<a href="http://wiki.squirrel-lang.org/default.aspx/SquirrelWiki/SQDBG.html">SQDBG远程调试库</a></p> <p>3. 将sqdbg工程放到SQUIRREL3之下,打开SQUIRREL3\squirrel.sln,将sqdbg添加到工程,编译所有</p> <p>4. 在这个Solution下,创建一个Squirrel松鼠工程</p> <p><a href="http://www.cppblog.com/images/cppblog_com/sunicdavy/WindowsLiveWriter/Squirrel_F936/image_2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.cppblog.com/images/cppblog_com/sunicdavy/WindowsLiveWriter/Squirrel_F936/image_thumb.png" width="459" height="96"></a></p> <p>5. 在新创建的松鼠工程属性中如下图设置</p> <p><a href="http://www.cppblog.com/images/cppblog_com/sunicdavy/WindowsLiveWriter/Squirrel_F936/image_4.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.cppblog.com/images/cppblog_com/sunicdavy/WindowsLiveWriter/Squirrel_F936/image_thumb_1.png" width="535" height="215"></a>&nbsp; </p> <p>Interpreter其实就是启动调试器(不是sq.exe)</p> <p>WorkingDirectory 就是main.nut所在的目录(官网的路径设置有点误导)</p> <p>Command Line Options 就是传入sqdbg.exe的命令行参数</p> <p>修改下main.nut文件,例如:</p> <p>for(local i = 1;i&lt;10;i++)<br>{<br>&nbsp;&nbsp;&nbsp; print( i );<br>}</p> <p>在print语句前打上断点,调试松鼠工程,即可看到调试结果</p> <p><a href="http://www.cppblog.com/images/cppblog_com/sunicdavy/WindowsLiveWriter/Squirrel_F936/image_8.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.cppblog.com/images/cppblog_com/sunicdavy/WindowsLiveWriter/Squirrel_F936/image_thumb_3.png" width="361" height="180"></a> </p> <p>&nbsp;</p> <p>有关于SQDBG多文件调试:</p> <p>SQDBG默认只能调试1个文件,显然是个玩具,不能应对游戏和其他领域的多文件调试. 分析了下SQDBG的代码</p> <div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">int</span> main(<span class="kwrd">int</span> argc, <span class="kwrd">char</span> *argv[])</pre><pre><span class="lnum">   2:  </span>{</pre><pre class="alt"><span class="lnum">   3:  </span>    <span class="kwrd">if</span>(argc &lt; 2){</pre><pre><span class="lnum">   4:  </span>        scprintf(_SC(<span class="str">"SQDBG error : no file specified"</span>));</pre><pre class="alt"><span class="lnum">   5:  </span>        <span class="kwrd">return</span> -1;</pre><pre><span class="lnum">   6:  </span>    }</pre><pre class="alt"><span class="lnum">   7:  </span>        </pre><pre><span class="lnum">   8:  </span>    HSQUIRRELVM v = sq_open(1024);</pre><pre class="alt"><span class="lnum">   9:  </span>    sqstd_seterrorhandlers(v);</pre><pre><span class="lnum">  10:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">  11:  </span>    <span class="rem">//!! INITIALIZES THE DEBUGGER ON THE TCP PORT 1234</span></pre><pre><span class="lnum">  12:  </span>    <span class="rem">//!! ENABLES AUTOUPDATE</span></pre><pre class="alt"><span class="lnum">  13:  </span>    HSQREMOTEDBG rdbg = sq_rdbg_init(v,1234,SQTrue);</pre><pre><span class="lnum">  14:  </span>    <span class="kwrd">if</span>(rdbg) {</pre><pre class="alt"><span class="lnum">  15:  </span>&nbsp;</pre><pre><span class="lnum">  16:  </span>        <span class="rem">//!! ENABLES DEBUG INFO GENERATION(for the compiler)</span></pre><pre class="alt"><span class="lnum">  17:  </span>        sq_enabledebuginfo(v,SQTrue);</pre><pre><span class="lnum">  18:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">  19:  </span>        sq_setprintfunc(v,printfunc,errorfunc);</pre><pre><span class="lnum">  20:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">  21:  </span>        <span class="rem">//!! SUSPENDS THE APP UNTIL THE DEBUGGER CLIENT CONNECTS</span></pre><pre><span class="lnum">  22:  </span>        <span class="kwrd">if</span>(SQ_SUCCEEDED(sq_rdbg_waitforconnections(rdbg))) {</pre><pre class="alt"><span class="lnum">  23:  </span>            scprintf(_SC(<span class="str">"connected\n"</span>));</pre><pre><span class="lnum">  24:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">  25:  </span>            <span class="kwrd">const</span> SQChar *fname=NULL;</pre><pre><span class="lnum">  26:  </span>#ifdef _UNICODE</pre><pre class="alt"><span class="lnum">  27:  </span>            SQChar sTemp[256];</pre><pre><span class="lnum">  28:  </span>            mbstowcs(sTemp,argv[1],(<span class="kwrd">int</span>)strlen(argv[1])+1);</pre><pre class="alt"><span class="lnum">  29:  </span>            fname=sTemp;</pre><pre><span class="lnum">  30:  </span><span class="preproc">#else</span></pre><pre class="alt"><span class="lnum">  31:  </span>            fname=argv[1];</pre><pre><span class="lnum">  32:  </span><span class="preproc">#endif</span> </pre><pre class="alt"><span class="lnum">  33:  </span>            <span class="rem">//!!REGISTERS STANDARDS LIBS</span></pre><pre><span class="lnum">  34:  </span>            sq_pushroottable(v);</pre><pre class="alt"><span class="lnum">  35:  </span>            sqstd_register_bloblib(v);</pre><pre><span class="lnum">  36:  </span>            sqstd_register_iolib(v);</pre><pre class="alt"><span class="lnum">  37:  </span>            <span class="rem">//!!EXECUTE A SCTIPT</span></pre><pre><span class="lnum">  38:  </span>            <span class="kwrd">if</span>(SQ_FAILED(sqstd_dofile(v,fname,SQFalse,SQTrue))) {</pre><pre class="alt"><span class="lnum">  39:  </span>                PrintError(v);</pre><pre><span class="lnum">  40:  </span>                _getch();</pre><pre class="alt"><span class="lnum">  41:  </span>            }</pre><pre><span class="lnum">  42:  </span>        }</pre><pre class="alt"><span class="lnum">  43:  </span>        <span class="rem">//!! CLEANUP</span></pre><pre><span class="lnum">  44:  </span>        sq_rdbg_shutdown(rdbg);</pre><pre class="alt"><span class="lnum">  45:  </span>    }</pre><pre><span class="lnum">  46:  </span>    <span class="kwrd">else</span> {</pre><pre class="alt"><span class="lnum">  47:  </span>        PrintError(v);</pre><pre><span class="lnum">  48:  </span>    }</pre><pre class="alt"><span class="lnum">  49:  </span>    sq_close(v);</pre></div>
<p>发现写这个库的老外还是很认真的,使用了sq_rdbg作为debugger的api前缀,意味着这个库代码是可以复用的.</p>
<div class="csharpcode">注意第38行:</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></p>
<p> sqstd_dofile(v,fname,SQFalse,SQTrue)</p>
<p>这就是SQDBG只能debug 1个文件的原因.</p>
<p>如果需要在项目中做远程调试,只需要将这句代码换为工程中加载所有脚本的代码和注册系统API代码即可</p>
<p>&nbsp;</p>
<p>当然,最简单的方法,直接在代码顶端添加dofile引用另外的代码即可</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/146376.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2011-05-14 17:42 <a href="http://www.cppblog.com/sunicdavy/archive/2011/05/14/146376.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>迷茫的游戏脚本选择 Lua, Google V8, Mono和 JavaScriptCore</title><link>http://www.cppblog.com/sunicdavy/archive/2011/05/14/146369.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sat, 14 May 2011 07:13:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2011/05/14/146369.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/146369.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2011/05/14/146369.html#Feedback</comments><slash:comments>24</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/146369.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/146369.html</trackback:ping><description><![CDATA[<p>最近正为游戏引擎选择一款较好的逻辑脚本而头疼不已</p> <p>1. Lua</p> <p>Lua用了5,6年的样子,从LuaPlus到lua-tinker再到lua_bind. 虽然lua本身很小巧方便,但是其不支持面向对象特性,让很多人在使用时模拟了很多面向对象的特性,但是这种做法在调试时简直是噩梦.</p> <p>我觉得游戏脚本最好是能预编译成byte code,让编译器在编译期将很多的bug暴露出来,而不是像lua那样.很多空访问错误必须要等到runtime才能暴露.让调试效率大大降低.这点,mono C#就是极好的选择.</p> <p>2. Mono</p> <p>由于Unity的流行,Mono被带入游戏开发者的视线内.其内置的很多系统脚本都是用C#写成,而且逻辑脚本用C#编写也是非常清晰严谨的.</p> <p>据说Mono在Windows下编译异常麻烦,而且嵌入方式也没有太多例子,现在这块严重缺乏资料.</p> <p>3. V8</p> <p>Google V8正是由于Chrome而风靡起来.直接JIT方式就是Chrome速度飞快的原因.</p> <p>最近down了一个下来试了下,果然名不虚传,API也非常的易用.不过由于不是很熟悉JavaScript的原因, 自己用scons编译出一个v8的shell,跑了一个带类继承的例子,居然不识别class关键字.这才感叹还不如用小巧的lua呢.在我看来,JavaScript与Lua比较,也就是个能new,但是没class的语言.也被别人称为半吊子面向对象,都是使用prototype方式来实现类功能.</p> <p>4. JavaScriptCore</p> <p>在Google V8的类测试碰壁后,马上研究了下Unity下的JavaScript到底用了什么库,没错就是Apple Safari里的JavaScriptCore. 这东西资料比Mono还少,都是高龄库了.想必整合不是一般的麻烦.但是还是不确定这个脚本引擎是否原生支持类</p> <p>5. Python</p> <p>Python? 没想过这种格式诡异的语言,正如Unity里支持Boo(一种很类似Python的语言)很少有人用一样, 上次用过Python是在一个build系统里, 游戏里是不会考虑这种脚本系统的,效率也是很大的原因.</p> <p>6. AngleScript, GameMonkey</p> <p>这两种语言都是很老的游戏脚本语言,不过都是类c++方式的,不过由于项目使用不多,或许是有一定的bug,资料也相对较少,所以可能最后考虑</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/146369.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2011-05-14 15:13 <a href="http://www.cppblog.com/sunicdavy/archive/2011/05/14/146369.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Lua 5.2 work5 更新，解决数制转换问题</title><link>http://www.cppblog.com/sunicdavy/archive/2010/11/14/133613.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Sun, 14 Nov 2010 14:07:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2010/11/14/133613.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/133613.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2010/11/14/133613.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/133613.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/133613.html</trackback:ping><description><![CDATA[<p>主要修改：</p> <p>更新了文档（这是必须的）</p> <p><strong>新的无符号整数C API</strong></p> <p>位处理函数重命名</p> <p><strong>更好及更快的支持双精度浮点数转换为整型</strong></p> <p>&nbsp;</p> <p>原文<strong><a href="http://lua-users.org/lists/lua-l/2010-10/msg00834.html">在此</a></strong></p> <p>&nbsp;</p> <p>可以看到，我在年初发文指出的lua数字处理方面的bug已经得到很好的解决，不过这种解决方法只是添加了api而已，看来还是没有松鼠脚本处理的彻底，原文<a href="http://www.cppblog.com/sunicdavy/archive/2010/02/04/107161.html"><strong>在此</strong></a></p><img src ="http://www.cppblog.com/sunicdavy/aggbug/133613.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2010-11-14 22:07 <a href="http://www.cppblog.com/sunicdavy/archive/2010/11/14/133613.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>设计D3D9 HLSL渲染脚本</title><link>http://www.cppblog.com/sunicdavy/archive/2010/02/15/107911.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Mon, 15 Feb 2010 15:18:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2010/02/15/107911.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/107911.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2010/02/15/107911.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/107911.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/107911.html</trackback:ping><description><![CDATA[<p>最近翻出很早之前自己写的一套使用Direct3D 9&nbsp; Effect系统的纯shader 3d引擎，打算使用最新技术重写。重写的主要修改在于：</p> <p>1. 去掉Effect系统，改用HLSL + 渲染脚本</p> <p>2. 优化渲染接口，使用材质统一shader和渲染状态</p> <p>随即参考了DirectX SDK的Graphics部分文档：DirectX9 时代的Effect系统纯粹只是一个HLSL的简单渲染脚本实现，除了DXUT，FXComposer等极少程序使用这套东西外，大型的引擎很少使用这种半成品系统。到了DirectX10甚至11，因为架构更改，去掉固定管线，因此Effect成为较为高效和便捷的渲染脚本，如果不是要求较高的3d引擎，一般的游戏使用DirectX10的Effect渲染脚本还是很不错的。</p> <p>DX10的fx脚本与DX9的差异在于</p> <p>渲染状态，采样器状态等都变为对象，并与API高度统一</p> <p>在脚本与API中均可以设置</p> <p>DepthStencilState EnableDepth<br>{<br>&nbsp;&nbsp;&nbsp; DepthEnable = TRUE;<br>&nbsp;&nbsp;&nbsp; DepthWriteMask = ALL;<br>&nbsp;&nbsp;&nbsp; DepthFunc = LESS_EQUAL;<br>};  <p>BlendState NoBlending<br>{<br>&nbsp;&nbsp;&nbsp; AlphaToCoverageEnable = FALSE;<br>&nbsp;&nbsp;&nbsp; BlendEnable[0] = FALSE;<br>}; <p>technique10 Render<br>{<br>&nbsp;&nbsp;&nbsp; pass P0<br>&nbsp;&nbsp;&nbsp; {</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetDepthStencilState( EnableDepth, 0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );<br>&nbsp;&nbsp;&nbsp; }<br>}</p> <p>本人觉得，这样的设计让图形API更为敏捷与归类化，另外，也便于StateManager或者自己做渲染状态转移及差异比较时更为高效 <p>&nbsp; <p>Vista操作系统推出很久后，DX10的显卡也占有了大量的市场份额。但是由于DX10仍然是一个过渡API（类似于DX8)，因此，很多3D游戏要么仍然支持DX9，要不然即支持DX9也支持DX10，甚至DX11. <p>&nbsp;&nbsp; 看博客上有达人组团编写类似DX10接口和系统的软渲染，DX10的设计是优秀的。因此，在DX9 HLSL基础上，结合自己编写的渲染脚本会是非常好的选择。 <p>&nbsp;&nbsp;&nbsp; 渲染脚本我的设计思路是这样的： <p> 1. 只是一种预处理脚本，并非实时运行脚本。 <p>编译器将文本解析后，转化为一些运行指令，比如：本pass使用一块小纹理，下一pass的target是这个纹理，并且开启哪些渲染状态。 <p>2. 自定义格式的解析脚本。 <p>使用lua，python等脚本其实也是可以的。但是在出现错误时，报出的错可能会让不熟悉这个脚本语言的人莫名其妙。 <p>使用松鼠sq脚本语言？可惜其在lua基础上，对table的slot初次赋值时必须使用&lt;-而不是统一使用=，因此会让你的脚本稀奇古怪 <p>XML脚本？ XML可以避免复杂的语法检查，写完就是归整的，但也是罗嗦的，本来Texture[2]可以表达完毕的，非要&lt;Texture index = 2/&gt;来罗嗦下。 <p>OGRE的compositor脚本和材质脚本就是自己解析的，不过出乎预料的使用了BNF范式这类较为正规的方法。这就是说，需要先解析BNF表达式，然后再输入脚本解析，编写过程和系统复杂度会变得异常复杂。 <p>最终选择还是使用自己解析的脚本，使用一些具体代码结构来替代BNF这类高深的东西 <p>决定以后，下一步需要制定渲染脚本具体各部分及制作过程 <p>1. 基本lexer <p>&nbsp;&nbsp; 从文本得到各种token <p>1. 渲染状态对象 <p>&nbsp;&nbsp; 照着DX10抄就好 <p>2. Shader导入口 <p>&nbsp;&nbsp;&nbsp;&nbsp; shader文件来自于何处，入口怎样定义 <p>3. 渲染脚本VM及指令 <p>&nbsp; 决定一个纹理怎样设置，RenderTarget怎样使用等的指令 <img src ="http://www.cppblog.com/sunicdavy/aggbug/107911.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2010-02-15 23:18 <a href="http://www.cppblog.com/sunicdavy/archive/2010/02/15/107911.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>LemonComposer  2D游戏动画开发工具</title><link>http://www.cppblog.com/sunicdavy/archive/2010/02/05/107257.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Fri, 05 Feb 2010 06:58:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2010/02/05/107257.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/107257.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2010/02/05/107257.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/107257.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/107257.html</trackback:ping><description><![CDATA[<p>Lemon是本人开发的一套适用于2D游戏动画和高级游戏框架及配套编辑器（LemonComposer）</p> <blockquote> <p>Lemon系统特性：</p> <p>1. 支持 Canvas,Sprite,ImageSet（图片帧存储于一张图片，等大小）</p> <p>2. ImageSetEx（自由摆放的图片帧于一张图片）*</p> <p>3. 支持对象无关键帧时使用静态属性进行设置，类似于HGE里的精灵</p> <p>4. 每个对象均可成为Container，并拥有Child Node</p> <p>5. 动画关键帧类型支持：缩放，旋转，位移，颜色，动画帧，锚点，音效*</p> <p>6. 支持拾取</p> <p>7. 基于XML存储的文件格式</p> <p>8. 基于<a href="http://squirrel-lang.org/">Squirrel</a>松鼠脚本的高速面向对象脚本*</p> <p>9. 图形系统Graphics抽象，适用于任何渲染设备</p> <p>10. 控件系统*</p> <p>11. 视频回放*</p> <p>所有对象均由RTTI创建，枚举均有NamePool+Hash，并由于PropertySet的反射系统</p> <p>&nbsp;</p></blockquote> <blockquote> <p>LemonComposer编辑器特性</p> <p>界面基于我去年开发的<a href="http://www.cppblog.com/sunicdavy/archive/2009/07/24/91059.html">MotionUI</a>，lua</p> <p>8+1控制点点对象调节属性</p> <p>类Adobe Flash的帧编辑。</p> <p>类3DS Max的分轨道关键帧编辑，有助于优化art assert</p> <p>自由调节对象层级及父子关系</p> <p>全功能无限制自由Redo,Undo</p> <p>&nbsp;</p></blockquote> <p>*将在未来版本支持</p> <p><a href="http://www.cppblog.com/images/cppblog_com/sunicdavy/WindowsLiveWriter/LemonComposer2D_D2B9/image_2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.cppblog.com/images/cppblog_com/sunicdavy/WindowsLiveWriter/LemonComposer2D_D2B9/image_thumb.png" width="483" height="300"></a> </p> <p>&nbsp;</p> <p>&nbsp;</p> <blockquote> <p>2D游戏是独立游戏的主流，也是创意，投入比最小的一个维度。但是基于2D的大多是一些类似于HGE，IndieLib等开源免费2D引擎。但是面对游戏中大量的动画而言，开发者大多是使用图片帧来制作，虽然效果很好，但是设备资源好用和制作难度也是很难控制的。</p></blockquote> <blockquote> <p>流行于去年的植物对僵尸和2004年发行的<a href="http://www.verycd.com/topics/51268/">RO Offline</a>经过资源分析，就是使用类似于Lemon系统，或者说Flash的系统制作而成，因此效果和扩展性非常好。</p> <p>这就是Lemon存在的理由。</p> <p>Flash面向的是GDI+Web，那么Lemon就是针对游戏专有的，基于硬件加速的游戏框架</p> <p>Flash Action Script 对应的就是Lemon的<a href="http://squirrel-lang.org/">Squirrel</a>脚本</p> <p>FlashIDE 对应的就是Lemon Composer</p> <p>Lemon的目标就是让2D游戏开发更简单，让游戏中充满更多的动画, 让游戏开发难度降低</p> <p><a href="http://www.cppblog.com/images/cppblog_com/sunicdavy/WindowsLiveWriter/LemonComposer2D_D2B9/farming-gold-in-pvz%5B1%5D_2.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="farming-gold-in-pvz[1]" border="0" alt="farming-gold-in-pvz[1]" src="http://www.cppblog.com/images/cppblog_com/sunicdavy/WindowsLiveWriter/LemonComposer2D_D2B9/farming-gold-in-pvz%5B1%5D_thumb.jpg" width="244" height="196"></a></p></blockquote><img src ="http://www.cppblog.com/sunicdavy/aggbug/107257.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2010-02-05 14:58 <a href="http://www.cppblog.com/sunicdavy/archive/2010/02/05/107257.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>批处理批量编译lua脚本</title><link>http://www.cppblog.com/sunicdavy/archive/2010/02/04/107187.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Thu, 04 Feb 2010 09:27:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2010/02/04/107187.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/107187.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2010/02/04/107187.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/107187.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/107187.html</trackback:ping><description><![CDATA[<p>for /r 路径 %%i in (匹配文件名) do 指令</p> <p>&nbsp;</p> <p>例子：</p> <p>for /r publish\ui\ %%i in (*.lua) do luac -o %%i %%i</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/107187.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2010-02-04 17:27 <a href="http://www.cppblog.com/sunicdavy/archive/2010/02/04/107187.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Lua脚本浮点转整形bug分析</title><link>http://www.cppblog.com/sunicdavy/archive/2010/02/04/107161.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Thu, 04 Feb 2010 04:49:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2010/02/04/107161.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/107161.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2010/02/04/107161.html#Feedback</comments><slash:comments>9</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/107161.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/107161.html</trackback:ping><description><![CDATA[<p>前面一片<a href="http://www.cppblog.com/sunicdavy/archive/2010/02/04/107155.html">文章</a>中lua出现的bug，其实是lua本身结构问题导致的：</p> <p>lua中，数值使用double来存储，包含整形和double。而解析出来的整形也是被强转为double进行存储，这样就会出问题。</p> <p>举一个简单的例子：</p> <p>double f = (double)0xffffffff;<br>int a = int(f);</p>a肯定不是-1 <p><a href="http://www.cnblogs.com/wodehuajianrui/archive/2009/03/18/1415173.html">这里</a>的文章说明这个类型转换问题的缘由。</p> <p>&nbsp;</p> <p>在<a href="http://squirrel-lang.org/">Squirrel</a>脚本中就不会有这个问题</p> <p>local a = 0xffffffff</p> <p>print( a )</p> <p>结果为-1</p> <p>查看其源代码：</p> <p>typedef union tagSQObjectValue<br>{<br>&nbsp;&nbsp;&nbsp; struct SQTable *pTable;<br>&nbsp;&nbsp;&nbsp; struct SQArray *pArray;<br>&nbsp;&nbsp;&nbsp; struct SQClosure *pClosure;<br>&nbsp;&nbsp;&nbsp; struct SQGenerator *pGenerator;<br>&nbsp;&nbsp;&nbsp; struct SQNativeClosure *pNativeClosure;<br>&nbsp;&nbsp;&nbsp; struct SQString *pString;<br>&nbsp;&nbsp;&nbsp; struct SQUserData *pUserData;<br>&nbsp;&nbsp;&nbsp; SQInteger nInteger;<br>&nbsp;&nbsp;&nbsp; SQFloat fFloat;<br>&nbsp;&nbsp;&nbsp; SQUserPointer pUserPointer;<br>&nbsp;&nbsp;&nbsp; struct SQFunctionProto *pFunctionProto;<br>&nbsp;&nbsp;&nbsp; struct SQRefCounted *pRefCounted;<br>&nbsp;&nbsp;&nbsp; struct SQDelegable *pDelegable;<br>&nbsp;&nbsp;&nbsp; struct SQVM *pThread;<br>&nbsp;&nbsp;&nbsp; struct SQClass *pClass;<br>&nbsp;&nbsp;&nbsp; struct SQInstance *pInstance;<br>&nbsp;&nbsp;&nbsp; struct SQWeakRef *pWeakRef;<br>&nbsp;&nbsp;&nbsp; SQRawObjectVal raw;<br>}SQObjectValue; <p>&nbsp;</p> <p>可以看到</p> <p>SQInteger nInteger;<br>SQFloat fFloat; <p>是分开存储的，因此就不会有这个问题</p> <p>&nbsp;</p> <p>lua解决方法：</p> <p>1. 将十六进制换为10进制存储</p> <p>2. 等待大侠或者官方修改代码，做出patch</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/107161.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2010-02-04 12:49 <a href="http://www.cppblog.com/sunicdavy/archive/2010/02/04/107161.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Lua在Release版本下的一个bug</title><link>http://www.cppblog.com/sunicdavy/archive/2010/02/04/107155.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Thu, 04 Feb 2010 02:59:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2010/02/04/107155.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/107155.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2010/02/04/107155.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/107155.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/107155.html</trackback:ping><description><![CDATA[<p>最近将自己的UI工程在Release版下编译，发现有部分控件的颜色居然偏黄，想必液晶也不至于老化的那么厉害，随机开始将工程加入调试信息进行跟踪，排除UI工程，及自己写的lua封装问题，将问题缩小为：</p> <p>lua代码：</p> <p>t = {} </p> <p>t.FillColor = 0xFFFFFFFF</p> <p>foo( t )</p> <p>在C++中注册一个foo函数，然后获取table t中的FillColor成员</p> <p>发现取得的值居然为0x80000000</p> <p>&nbsp;</p> <p>使用lua c api测试代码</p> <p>lua_newtable( L );<br>lua_setglobal( L, "t"); <p>lua_getglobal( L, "t");<br>lua_pushstring(L,"FillColor");<br>lua_pushinteger( L, 0xffffffff );<br>lua_pushinteger( L, -1 );<br>lua_settable( L, -3 );  <p>lua_getglobal( L, "t");<br>lua_pushstring( L, "FillColor");<br>lua_gettable( L, -2 );<br>int t = lua_tointeger( L, -1 ); <p>结果t也是0x80000000 <p>&nbsp; <p>然后将十六进制的0xFFFFFFFF换成十进制的4294967295，测试结果正确显示-1 <p>再使用几个样本测试 <p>0xFF5F5F5F = 4284440415 会被改成0xFF5F5F00 <p>&nbsp; <p>这个bug倒是很好解决，将代码中的十六进制数全换为10进制即可。但是为什么只在Release版本发生呢？ <p>本人使用的是lua 5.1.4 原生</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/107155.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2010-02-04 10:59 <a href="http://www.cppblog.com/sunicdavy/archive/2010/02/04/107155.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>为游戏系统选择一个接口方式</title><link>http://www.cppblog.com/sunicdavy/archive/2009/12/31/104543.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Thu, 31 Dec 2009 03:42:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2009/12/31/104543.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/104543.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2009/12/31/104543.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/104543.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/104543.html</trackback:ping><description><![CDATA[<p>&nbsp;&nbsp;&nbsp;&nbsp; 准备为自己的2D游戏动画系统选择一套给外部使用的接口方式，有如下几种选择：</p> <p>&nbsp;</p> <p>1. 纯C API方式导出，类似于Windows API方式</p> <p>优点：简洁，可以供C/C#乃至其他可以导入C DLL的语言使用</p> <p>缺点：C++的系统转化为C会遇到很多性能以及架构的折损，对于对象控制类功能导出比较多的系统，这种方式简直是噩梦</p> <p>&nbsp;</p> <p>2. C++方式导出，宏方式实现RTTI以及C++反射系统</p> <p>优点：强大，易用。</p> <p>缺点：对象生命周期不容易控制，反射系统设计比较费时，可能暴露很多类的细节，只能给C++使用</p> <p>&nbsp;</p> <p>3. COM方式，类DirectX的接口方式</p> <p>优点：商业项目已经证明这种接口方式的强大地方。无论是多个对象的类功能导出，还是COM接口重载都非常方便。而且，可以极为容易的让.NET访问。XBOX SDK里的XUI就是采用这种方式，而且还设计了一套C API搭配的强大C++反射系统，支持动态类创建，RTTI，动态类型转换等等。</p> <p>缺点：需要系统注册，不能跨平台。COM标准学习起来需要时间</p> <p>&nbsp;</p> <p>4. 脚本绑定</p> <p>优点：保持你的系统对外C/C++接口的干净，简洁。通过脚本类绑定，可以很快的将C++功能注册到脚本中。</p> <p>缺点：脚本如果没有调试器，将会让开发中碰到的棘手问题，甚至于在后期维护系统以及系统架构大变动变得异常复杂。脚本的性能决定了不能让其做实时处理，例如：渲染</p> <p>&nbsp;</p> <p> 最终选择下来，由于有自己的界面系统Motion使用lua的函数绑定的前例，因此还是决定选择一款脚本语言来做系统的对外接口，这里有几个选择：</p> <p>1. Lua</p> <p>&nbsp; 可以说最好的游戏系统脚本语言。稳定，高效，bug几乎没有（即便有，普通开发者也是很难察觉的）。配上LuaPlus的强大C++绑定系统，你的系统开发效率可以提高很多。这里推荐notepad++来做lua开发，稍微配置下，弹出提示给你感觉在使用Visual Studio，：）</p> <p>&nbsp;&nbsp; 同时需要指出的是，lua的类功能确实比较弱。虽然可以用metatable方式来模拟。但逼近跟native class支持还差很远，实际开发中，你能体会出class中的权限控制（private，protected）有多么重要。</p> <p>2. Python</p> <p>&nbsp;&nbsp; 诚然，这是个最OO的脚本。但是对于游戏，它太慢了。虽然本人只是用python写过一些build系统，但从很多朋友反应的情况来看，Python嵌入游戏系统，确实太慢。用Stackless Python？ 用第三方开源产品，还是认准品牌，呵呵，这里如果有用过的同学，欢迎提供感受。</p> <p>3. C#</p> <p>&nbsp;&nbsp; 语言和系统都很美，但是想嵌入游戏，还是很痛的。.net平台可惜就在于，到现在为止，可能还不是所有机器默认安装有.net平台。如果你的游戏是C++写成，但却要安装.net以便你的脚本能运行，这很奇怪吧？所以，如果要用C#，还不如不用脚本，全盘.net就好了。Managed DX？ 那东西几年前就被MS打入冷宫了。XNA？ 那东西只是一个玩具，别摸。</p> <p>4.<a href="http://squirrel-lang.org/">Squirrel</a>松鼠脚本</p> <p>&nbsp;&nbsp; 这是个好东西。类lua的语法，C/C++/Java的语言结构，纯正的native class外加OO支持。拥有开源的C++类绑定系统。最爽的是，<a href="http://wiki.squirrel-lang.org/default.aspx/SquirrelWiki/SQDEV.html">SQDEV</a>支持日食（Eclipse）下的远程调试，开发环境还支持动态语法检查。oh,my god。还说不定哪天这脚本被MS招安，跟IronPython一样弄个.net绑定。</p> <p>&nbsp;</p> <p><img src="http://wiki.squirrel-lang.org/myimages/debugger.png" width="568" height="451"></p><img src ="http://www.cppblog.com/sunicdavy/aggbug/104543.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2009-12-31 11:42 <a href="http://www.cppblog.com/sunicdavy/archive/2009/12/31/104543.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>虚幻引擎中的Kismet虚拟游戏逻辑编辑器资料</title><link>http://www.cppblog.com/sunicdavy/archive/2009/12/18/103480.html</link><dc:creator>战魂小筑</dc:creator><author>战魂小筑</author><pubDate>Fri, 18 Dec 2009 09:42:00 GMT</pubDate><guid>http://www.cppblog.com/sunicdavy/archive/2009/12/18/103480.html</guid><wfw:comment>http://www.cppblog.com/sunicdavy/comments/103480.html</wfw:comment><comments>http://www.cppblog.com/sunicdavy/archive/2009/12/18/103480.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/sunicdavy/comments/commentRss/103480.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunicdavy/services/trackbacks/103480.html</trackback:ping><description><![CDATA[<p>虚幻中有一套专门用于策划使用的逻辑开发工具：Kismet，号称无需编程就可以完成大部分的逻辑。最近正好在研究这方面的技术，所以找到了一些资料</p> <p>&nbsp;</p> <p>这是一个简单的教学，告诉你Kismet是怎么运行的</p> <p><a href="http://udn.epicgames.com/Three/KismetUserGuide.html">http://udn.epicgames.com/Three/KismetUserGuide.html</a></p> <p>&nbsp;</p> <p>这是Kismet的资料</p> <p><a href="http://udn.epicgames.com/Three/KismetReference.html">http://udn.epicgames.com/Three/KismetReference.html</a></p> <p>&nbsp;</p> <p>让我们来熟悉下</p> <p><img alt="event.jpg" src="http://udn.epicgames.com/Three/rsrc/Three/KismetUserGuide/event.jpg">这是一个Event节点，一般用于创建输入流，事件可以从Actor或者其他地方进入</p> <p>&nbsp;</p> <p><img alt="action.jpg" src="http://udn.epicgames.com/Three/rsrc/Three/KismetUserGuide/action.jpg">这是一个Action节点，动态的搭接输入条件，可以快速的输出你需要的结果</p> <p>&nbsp;</p> <p><img alt="condition.jpg" src="http://udn.epicgames.com/Three/rsrc/Three/KismetUserGuide/condition.jpg">这是一个Condition节点，用于根据输入，输出结果</p> <p>&nbsp;</p> <p><img alt="variable.jpg" src="http://udn.epicgames.com/Three/rsrc/Three/KismetUserGuide/variable.jpg">这是一个普通的变量，存储任何可以存储的对象</p> <p>&nbsp;</p> <p>第一个例子：</p> <p><img alt="simple_sequence.jpg" src="http://udn.epicgames.com/Three/rsrc/Three/KismetUserGuide/simple_sequence.jpg"></p> <p>这个例子要实现的是，玩家点击后，打开一盏灯</p> <p>玩家通过Event节点，产生一个输入流，这个流被连接到Togger（Action）的Turn On节点，注意，黑色的连接线表示“操作流”，而Togger的执行目标被接到了灯上，这样一个简单的逻辑就执行出来了</p> <p>&nbsp;</p> <p>动态绑定事件</p> <p><img alt="attach_event.jpg" src="http://udn.epicgames.com/Three/rsrc/Three/KismetUserGuide/attach_event.jpg"></p> <p>&nbsp;</p> <p></p> <p></p> <p></p> <p></p> <p></p> <p>有时你需要绑定的对象是不在编辑器里的，这个例子就是在游戏中动态创建一个Actor，要解决这个问题，就必须将物体连接到一个变量。</p> <p>当Actor Factory执行后，其生成一个新的Actor，并将其放置在一个对象数组中（图中的问号），然后，他会调用AttachToEvent action，将死亡事件连接到这个变量。 那么当这个Actor死亡时，事件就会被触发。</p> <p>&nbsp;</p> <p>先讲这些，呵呵，吃饭吃饭</p><img src ="http://www.cppblog.com/sunicdavy/aggbug/103480.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunicdavy/" target="_blank">战魂小筑</a> 2009-12-18 17:42 <a href="http://www.cppblog.com/sunicdavy/archive/2009/12/18/103480.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>