• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            李錦俊(mybios)的blog

            游戲開發(fā) C++ Cocos2d-x OpenGL DirectX 數(shù)學(xué) 計(jì)算機(jī)圖形學(xué) SQL Server

              C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              86 Posts :: 0 Stories :: 370 Comments :: 0 Trackbacks

            公告

            QQ:30743734
            EMain:mybios@qq.com

            常用鏈接

            留言簿(16)

            我參與的團(tuán)隊(duì)

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 370171
            • 排名 - 67

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            我在嘗試導(dǎo)出Ogre的所有類接口到lua中使用,參考CEGUI的方法,使用的是tolua++來(lái)導(dǎo)出C++類對(duì)象。在使用過(guò)程中,遇到了一些問(wèn)題。


            問(wèn)題1:
            表現(xiàn)為tolua++編譯錯(cuò)誤,錯(cuò)誤信息是:***curr code for error is $pfile "OgreBase/OgreVector2.h"

            這里我編寫了一個(gè)OgreBase.pkg文件(給tolua++用來(lái)生成導(dǎo)出導(dǎo)入lua的定義文件)
            namespace Ogre
            {
                $pfile 
            "OgreBase/OgreSharedPtr.h" 
                $pfile 
            "OgreBase/OgreVector2.h" 
            }
            ;
            OgreSharedPtr.h文件內(nèi)容如下:
            $#include "OgreSharedPtr.h"
            /// The method to use to free memory on destruction
            enum SharedPtrFreeMethod
            {
                
            /// Use OGRE_DELETE to free the memory
                SPFM_DELETE,
                
            /// Use OGRE_DELETE_T to free (only MEMCATEGORY_GENERAL supported)
                SPFM_DELETE_T,
                
            /// Use OGRE_FREE to free (only MEMCATEGORY_GENERAL supported)
                SPFM_FREE
            }
            ;

            class SharedPtr
            {
                TOLUA_TEMPLATE_BIND(T, Ogre::DataStream , Ogre::DataStreamList , Ogre::StringVector , Ogre::FileInfoList)

                SharedPtr();
                
            ~SharedPtr();
                T
            * get() ;
                
            void bind(T* rep, SharedPtrFreeMethod freeMethod = SPFM_DELETE);
                
            bool unique() ;
                unsigned 
            int useCount() ;
                T
            * getPointer() ;
                
            bool isNull(void) ;
                
            void setNull(void);
            }
            ;
            OgreVector2.h內(nèi)容如下:
            $#include "OgreVector2.h"


            class Vector2
            {
            public:
                Real x, y;

            public:
                inline Vector2();
                inline Vector2( Real fX,  Real fY );
                inline Vector2(  Vector2
            & rkVector );

                inline Real 
            operator [] (  size_t i ) ;

                inline Real
            & operator [] (  size_t i );
                inline Real
            * ptr();
                inline  Real
            * ptr() ;
                inline Vector2
            & operator = (  Vector2& rkVector );
                inline Vector2
            & operator = (  Real fScalar);

                inline 
            bool operator == (  Vector2& rkVector ) ;

                inline 
            bool operator != (  Vector2& rkVector ) ;
                inline Vector2 
            operator + (  Vector2& rkVector ) ;

                inline Vector2 
            operator - (  Vector2& rkVector ) ;
                inline Vector2 
            operator * (  Real fScalar ) ;

                inline Vector2 
            operator * (  Vector2& rhs) ;

                inline Vector2 
            operator / (  Real fScalar ) ;

                inline Vector2 
            operator / (  Vector2& rhs) ;

                inline  Vector2
            & operator + () ;

                inline Vector2 
            operator - () ;

                inline Real length () ;
                inline Real squaredLength () ;
                inline Real dotProduct( Vector2
            & vec) ;
                inline Real normalise();
                inline Vector2 midPoint(  Vector2
            & vec ) ;
                inline 
            bool operator < (  Vector2& rhs ) ;
                inline 
            bool operator > (  Vector2& rhs ) ;
                inline 
            void makeFloor(  Vector2& cmp );
                inline 
            void makeCeil(  Vector2& cmp );
                inline Vector2 perpendicular(
            void) ;
                inline Real crossProduct(  Vector2
            & rkVector ) ;
                inline Vector2 randomDeviant(
                    Real angle) ;
                inline 
            bool isZeroLength(void) ;
                inline Vector2 normalisedCopy(
            void) ;
                inline Vector2 reflect( Vector2
            & normal) ;
                
            // special points
                static const Vector2 ZERO;
                
            static const Vector2 UNIT_X;
                
            static const Vector2 UNIT_Y;
                
            static const Vector2 NEGATIVE_UNIT_X;
                
            static const Vector2 NEGATIVE_UNIT_Y;
                
            static const Vector2 UNIT_SCALE;

            }
            ;

            咋一看,沒(méi)任何問(wèn)題,但是編譯卻錯(cuò)誤。原因在于tolua++對(duì)$pfile的處理有些許問(wèn)題,它是直接把被包含文件粘貼到一個(gè)文件中,而OgreSharedPtr.h最后一行是};,結(jié)果};和$pfile "OgreBase/OgreVector2.h"連在一行中了,結(jié)果出現(xiàn)編譯錯(cuò)誤。解決辦法很簡(jiǎn)單,在每行$pfile之后加一行空行,或者在每個(gè)被包含頭文件后保證最后一行是空行即可。


            問(wèn)題2:
            tolua++對(duì)嵌套類模板的導(dǎo)出bug。編寫如下的pkg文件,為了導(dǎo)出一個(gè)有4個(gè)模板參數(shù)的std::map類到lua中,而4個(gè)模板參數(shù)中有個(gè)模板參數(shù)Ogre::STLAllocator帶有自身的模板參數(shù)嵌套,代碼如下:




            namespace Ogre
            {
                
            class STLAllocator
                
            {
                    TOLUA_TEMPLATE_BIND(T, 
            int , shortdouble, VECTOR3, std::string, IModelViewWrapper*, IDisplaySetting::Property, IDisplaySetting::DisplaySize, IDisplaySetting::AntiAliasingLevel, DataStreamPtr, Plane, PlaneBoundedVolume, Polygon*, std::pair<std::string Ogre::BaseResourceGroupManager::ArchiveIndexEntry>, std::pair<std::string Ogre::BaseResourceGroupManager::BaseResourceGroup*>, Ogre::BaseResourceGroupManager::ResourceLocation*)
                }
            ;
                
            }
            ;
            namespace std
            {
                
            class less
                
            {
                    TOLUA_TEMPLATE_BIND(T,std::
            string)
                }
            ;
                
                
            class pair
                
            {
                    TOLUA_TEMPLATE_BIND(F S,std::
            string Ogre::BaseResourceGroupManager::ArchiveIndexEntry)
                    pair();
                    
            ~pair();
                    F first;
                    S second;
                }
            ;
                
                
            class map 
                
            {
                    TOLUA_TEMPLATE_BIND(K V S A,std::
            string Ogre::BaseResourceGroupManager::ArchiveIndexEntry std::less<std::string> Ogre::STLAllocator<std::pair<std::string,Ogre::BaseResourceGroupManager::ArchiveIndexEntry> >)
                    
                    
            class iterator
                    
            {
                        pair
            <K,V> operator->();
                    }
            ;
                    
                    
            void clear();
                    
            bool empty();
                    
            int size() ;
                    
                    std::map
            <K,V,S,A>::iterator find( K &key);
                    std::map
            <K,V,S,A>::iterator begin();
                    std::map
            <K,V,S,A>::iterator end();
                    std::map
            <K,V,S,A>::reverse_iterator rbegin();
                    std::map
            <K,V,S,A>::reverse_iterator rend();
                    
                    std::pair
            <std::map<K,V,S,A>::iterator,bool> insert( std::pair<K,V> &value);
                    std::map
            <K,V,S,A>::iterator erase(std::map<K,V,S,A>::iterator iter);
                    
                    
                    map();
                    
            ~map();
                }
            ;

            }
            ;

            用tolua++編譯這個(gè)pkg文件,生成cpp文件時(shí)不會(huì)出錯(cuò),但編譯cpp文件時(shí)會(huì)出錯(cuò),因?yàn)樗傻腸pp文件中,模板嵌套的代碼有問(wèn)題,如下:

            生成的錯(cuò)誤代碼片段1:
            std::map
            <std::string ,Ogre::BaseResourceGroupManager::ArchiveIndexEntry ,std::less<std::string> ,Ogre::STLAllocator<std::pair<std::string,Ogre::BaseResourceGroupManager::ArchiveIndexEntry> >>

            生成的錯(cuò)誤代碼片段2:
            std::map
            <std::string ,Ogre::BaseResourceGroupManager::ArchiveIndexEntry ,std::less<std::string> ,Ogre::STLAllocator<std::pair<std::string,Ogre::BaseResourceGroupManager::ArchiveIndexEntry> >,>
            這兩段錯(cuò)誤代碼中,第一個(gè)代碼片段最后兩個(gè)尖括號(hào)連接在一起了,錯(cuò)誤在于最后兩個(gè)尖括號(hào)間沒(méi)有空格。
            第二個(gè)代碼片段最后兩個(gè)尖括號(hào)間多了個(gè)“,”符號(hào)。
            檢查發(fā)現(xiàn),是tolua++代碼本身有bug,修復(fù)如下:
            打開tolua++目錄的lua目錄,打開class.lua文件,181行append = string.gsub(append, ">>", "> >"),這里目的是把兩個(gè)尖括號(hào)間加空格,但它沒(méi)考慮到把這個(gè)類型與另一個(gè)模板類型嵌套使用的情況,結(jié)果出現(xiàn)代碼片段1的bug,解決辦法是改成append = string.gsub(append, ">>", "> > "),即在最后一個(gè)尖括號(hào)后自動(dòng)加一個(gè)空格,以解決此問(wèn)題,187行也有同樣的問(wèn)題,改成bI = string.gsub(bI, ">>", "> > ")即可。
            對(duì)于錯(cuò)誤的代碼片段2,需要打開declaration.lua,定位到148行,改成local template_part = "<"..concat(m, 1, m.n , ",")..">",這樣就能解決代碼片段2的問(wèn)題,此問(wèn)題的起因在于此地方用空格來(lái)做模板參數(shù)的分隔符,但模板尖括號(hào)間又有空格,結(jié)果把這個(gè)空格自動(dòng)替換成逗號(hào),導(dǎo)致編譯錯(cuò)誤。


            最后,由于Ogre庫(kù)比較龐大,暫時(shí)我只完成了Ogre基本庫(kù)(數(shù)學(xué)庫(kù)、字符串、文件系統(tǒng)等等渲染無(wú)關(guān)系統(tǒng))的功能導(dǎo)出到lua,還沒(méi)把渲染層導(dǎo)出。


            如果本文對(duì)你的開發(fā)有所幫助,并且你手頭恰好有零錢。

            不如打賞我一杯咖啡,鼓勵(lì)我繼續(xù)分享優(yōu)秀的文章。




            posted on 2010-02-09 19:43 李錦俊(mybios) 閱讀(7243) 評(píng)論(7)  編輯 收藏 引用 所屬分類: LUA

            Feedback

            # re: tolua++導(dǎo)出C++類的一些問(wèn)題和解決方法 2010-02-10 09:38 akunspy
            沒(méi)這樣用lua的
            這需求本身就有問(wèn)題...  回復(fù)  更多評(píng)論
              

            # re: tolua++導(dǎo)出C++類的一些問(wèn)題和解決方法 2010-02-10 13:06 mybios
            @akunspy
            不吝賜教,請(qǐng)問(wèn)這樣用lua有什么問(wèn)題?  回復(fù)  更多評(píng)論
              

            # re: tolua++導(dǎo)出C++類的一些問(wèn)題和解決方法 2010-02-13 17:11 陳梓瀚(vczh)
            從編譯器開發(fā)者的的角度上講,這樣沒(méi)問(wèn)題  回復(fù)  更多評(píng)論
              

            # re: tolua++導(dǎo)出C++類的一些問(wèn)題和解決方法 2011-01-05 13:01 libla
            這不過(guò)是把C++的皮換成lua而已,對(duì)于程序開發(fā)來(lái)說(shuō),除了降低執(zhí)行效率,不會(huì)帶來(lái)其他好處,寫lua就和寫C++沒(méi)區(qū)別  回復(fù)  更多評(píng)論
              

            # re: tolua++導(dǎo)出C++類的一些問(wèn)題和解決方法 2011-02-17 17:27 朱江波
            樓主這兩個(gè)問(wèn)題我都碰到過(guò),只是當(dāng)時(shí)不求甚解,沒(méi)深究,避而不用。現(xiàn)在學(xué)習(xí)了,多謝樓主。  回復(fù)  更多評(píng)論
              

            # re: tolua++導(dǎo)出C++類的一些問(wèn)題和解決方法 2015-04-04 22:09 周瑞
            非常感謝!!如果不看這篇文章的話,可能我一個(gè)月也找不出問(wèn)題在哪兒  回復(fù)  更多評(píng)論
              

            # re: tolua++導(dǎo)出C++類的一些問(wèn)題和解決方法 2016-03-18 17:51 play_with_wolf
            能否開源一下Ogre基本庫(kù)的pkg文件么  回復(fù)  更多評(píng)論
              

            久久99精品国产麻豆蜜芽| 国产成人精品综合久久久| 久久久精品人妻一区二区三区蜜桃| 久久久久久久免费视频| 波多野结衣久久精品| 精品伊人久久久| 亚洲国产精品无码久久一区二区| 久久精品一本到99热免费| 亚洲精品午夜国产VA久久成人| 亚洲精品无码久久久久去q| 久久精品aⅴ无码中文字字幕不卡| 99久久免费国产精精品| 99久久精品国产综合一区 | 久久综合丁香激情久久| 大蕉久久伊人中文字幕| 久久精品无码一区二区三区日韩| 手机看片久久高清国产日韩| 久久狠狠爱亚洲综合影院| 久久99精品国产自在现线小黄鸭 | 久久精品国产亚洲网站| 国产精品99久久不卡| 狠狠色丁香久久婷婷综合蜜芽五月| 99精品久久久久久久婷婷 | 久久久精品免费国产四虎| 久久精品国产亚洲av瑜伽| 2021最新久久久视精品爱| 国产精品久久久久国产A级| 久久精品成人免费观看97| 久久亚洲AV无码精品色午夜麻豆| 精品久久久久久亚洲精品| 精品综合久久久久久88小说| 久久精品国产免费观看 | 国产精品热久久毛片| 色综合久久88色综合天天 | 18岁日韩内射颜射午夜久久成人| 色婷婷狠狠久久综合五月| 久久香蕉超碰97国产精品| 久久久久18| 国产亚洲欧美成人久久片| 一97日本道伊人久久综合影院| 久久精品aⅴ无码中文字字幕不卡|