• <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ù)學 計算機圖形學 SQL Server

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

            公告

            QQ:30743734
            EMain:mybios@qq.com

            常用鏈接

            留言簿(16)

            我參與的團隊

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 370223
            • 排名 - 67

            最新評論

            閱讀排行榜

            評論排行榜

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


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

            這里我編寫了一個OgreBase.pkg文件(給tolua++用來生成導(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;

            }
            ;

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


            問題2:
            tolua++對嵌套類模板的導(dǎo)出bug。編寫如下的pkg文件,為了導(dǎo)出一個有4個模板參數(shù)的std::map類到lua中,而4個模板參數(shù)中有個模板參數(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++編譯這個pkg文件,生成cpp文件時不會出錯,但編譯cpp文件時會出錯,因為它生成的cpp文件中,模板嵌套的代碼有問題,如下:

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

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


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


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

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




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

            Feedback

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

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

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

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

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

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

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

            久久久精品免费国产四虎| 久久涩综合| 午夜精品久久久久9999高清| 无码久久精品国产亚洲Av影片 | 久久综合五月丁香久久激情| 久久久一本精品99久久精品66| 色综合久久中文字幕综合网| 女人香蕉久久**毛片精品| 亚洲AV无码1区2区久久| 久久精品国产欧美日韩| 欧美亚洲另类久久综合| 少妇精品久久久一区二区三区| 久久av免费天堂小草播放| 亚洲精品高清久久| 91精品国产91久久综合| 久久久久人妻一区精品色| 中文字幕无码免费久久| 亚洲精品无码专区久久同性男| 久久九九久精品国产免费直播| AA级片免费看视频久久| 老司机国内精品久久久久| 久久免费视频网站| 国产精品成人99久久久久 | 日韩精品久久无码人妻中文字幕| 伊人久久大香线蕉无码麻豆| 久久久久久久久久免免费精品| 国产亚州精品女人久久久久久 | 四虎国产永久免费久久| 欧美久久久久久| 久久se精品一区精品二区| 中文成人无码精品久久久不卡| AV无码久久久久不卡蜜桃| 伊人色综合九久久天天蜜桃| 久久AV高清无码| 伊人情人综合成人久久网小说| 久久久久久久综合日本亚洲| 久久久久久久波多野结衣高潮| 久久国产精品久久国产精品| 日本欧美久久久久免费播放网 | 日韩乱码人妻无码中文字幕久久| 国产亚洲美女精品久久久|