• <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>

            戰(zhàn)魂小筑

            討論群:309800774 知乎關(guān)注:http://zhihu.com/people/sunicdavy 開源項目:https://github.com/davyxu

               :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              257 隨筆 :: 0 文章 :: 506 評論 :: 0 Trackbacks

             

            最近準(zhǔn)備在手機項目客戶端中使用lua, 以前一直在服務(wù)器使用luabind. 另外, tolua++也體驗過, LuaPlus也在早年用過. 以下是本人對這些綁定庫的個人感覺:

            luabind

            利用boost機制把綁定做到極致, 比較適合主c++, 弱lua的腳本框架.

            作者已經(jīng)停止更新, 在windows/linux編譯沒問題, 但是在ios的LLVM下, 無法編譯

            tolua++

            像cocos2dx使用tolua++也是可以理解的, 那么多函數(shù)需要綁定, tolua++的頭文件parse及自動代碼生成節(jié)約了很多手動綁定的時間.

            但是看到代碼中有一部分bugfix就心存不安(純個人感覺, 本人使用不多, 歡迎磚頭伺候),另外, tolua++只能由腳本層驅(qū)動C++, 而沒有將已經(jīng)實例化的句柄注冊到lua的功能也是煞筆啊

             

            LuaPlus

            接口較為簡單, 適于初學(xué)者上手, 無任何的模板, 性能不高

             

            luaBridge

            項目地址: https://github.com/vinniefalco/LuaBridge

            手冊: http://vinniefalco.com/LuaBridge/Manual.html

            純頭文件實現(xiàn), 無需編譯, 包含進入工程即可, 接口簡潔高效

            相比luabind, 唯一不能實現(xiàn)的常用功能就是枚舉, 但是可以支持類成員靜態(tài)變量注冊, 這個就無所謂了, 手寫一個枚舉支持也很簡單

            看下演示代碼:

            class A
            {
            public:
                A( )
                {
            
                }
                virtual void foo( int a )
                {
                    printf("foo base\n");
                }
            
                std::string Member;
            };
            
            class B : public A
            {
            public:
                virtual void foo( int a )
                {
                    printf("foo inherited\n");
                }
            };
            
            void foo( int b )
            {
            
            }
            

            luabridge::getGlobalNamespace(L)
                    .beginClass<A>("Sobj")
                        .addConstructor<void (*) (void)> ()
                        .addFunction("foo", &A::foo)
                        .addData("Member",&A::Member)
                    .endClass()
                    .deriveClass<B, A>("SSec")
                        .addFunction("foo",&B::foo )
                    .endClass();
            
                luabridge::getGlobalNamespace(L).addFunction("foo", foo );
            
            
                B ins;
                ins.Member = "data";
                luabridge::setGlobal(L, ins, "ins");

            lua側(cè)的代碼
            
            local a = Sobj()
            a:foo(2)
            a.Member = "hello"
            
            
            ins:foo(3)
            
            posted on 2013-12-07 14:05 戰(zhàn)魂小筑 閱讀(12335) 評論(24)  編輯 收藏 引用 所屬分類: 腳本技術(shù)C++/ 編程語言

            評論

            # re: 超越luabind的luaBridge[未登錄] 2013-12-08 22:44 微妙的平衡
            這個不錯  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2013-12-09 00:26 楊粼波
            我用過的棒子貨LuaTinker倒是不錯.
            這個可以嘗試下...  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2013-12-09 09:47 戰(zhàn)魂小筑
            我也用過, 但是用過luabridge后, 那貨也就放箱底了@楊粼波
              回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2013-12-13 17:38 力為
            還在用luabind。
            貌似有人繼續(xù)維護吧?  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2014-01-03 21:44 戰(zhàn)魂小筑
            開源的,自己改也沒問題。況且這段時間用下來沒啥問題@力為
              回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2014-03-13 16:20 sthouwu
            哈哈,之前端游項目就是用的LuaBridge。  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 09:26 phantom
            luabridge綁定的成員函數(shù),如果參數(shù)個數(shù)大于1個,從腳本調(diào)用直接就crash,你沒有遇到這個問題?  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 09:29 phantom
            我就是看你這個博客才用的luabridge,結(jié)果一試,這個問題太明顯,而且更妙的是,官方demo沒有一個超過2參的例子,不得不承認這庫真是太傻逼了。  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 09:31 戰(zhàn)魂小筑
            @phantom
            我用的非常正常, 沒發(fā)現(xiàn)有什么問題
            1. 沒改源碼
            2. 都參考官方例子使用
            碰到問題, 貼出代碼來才是王道, 人家也是測了很久才發(fā)的
            發(fā)現(xiàn)問題就罵庫, 繞半天才發(fā)現(xiàn)是自己的問題  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 13:19 phantom
            @戰(zhàn)魂小筑
            謝謝你回復(fù)這么快,我傳到百度盤了,代碼很少
            http://pan.baidu.com/s/1c0c62ru
            owcmn.h忘了打包給個github地址
            https://github.com/bhlzlx/graphics/blob/master/ow/owcmn/owcmn.h
            別外,我直接下載的luabridge最新版,有編譯錯誤,pushstring的地方要改成pushlstring才編譯過去。
            所以我才好煩啊,寫個庫最基本的都有問題感覺,所以才來請教大神,有沒有遇到這樣的問題。  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 13:27 戰(zhàn)魂小筑
            @phantom
            調(diào)用lua用luabridge也就是一句話, 干嘛寫個scriptengine又封裝一層...
            你把官方的例子照著跑一遍, 別封裝了, 速度慢不說, 經(jīng)常搞出的錯誤全是自己搞的

            代碼能否搞個直接可以編譯的, 給你看代碼比開源代碼都麻煩, 無法編譯  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 13:36 phantom
            注冊的代碼在這
            .beginClass<ow::MemBuffer>( "MemBuffer" )
            .addFunction( "Size", &ow::MemBuffer::Size )
            .addFunction( "Seek", &ow::MemBuffer::Seek )
            .addFunction( "Read", &ow::MemBuffer::Read )
            .addFunction<owINT32 (ow::MemBuffer::*)( const owVOID*,owINT32 )>( "Write", &ow::MemBuffer::Write )
            .addFunction( "Resize", &ow::MemBuffer::Resize )
            .addFunction( "Eof", &ow::MemBuffer::Eof )
            .addFunction( "GetCurr", &ow::MemBuffer::GetCurr )
            .addFunction( "GetBuffer", &ow::MemBuffer::GetBuffer )
            .addFunction( "Release", &ow::MemBuffer::Release )
            .endClass()
            MemBuffer的定義在buffer.h里,單獨測試一下這個write方法就好。  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 13:42 phantom
            我這是用codelite + gcc寫的,要不我做一個vs2010的工程給你看。  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 13:55 phantom
            vs2010下載下來直接就可以編譯,宏我也展開了,方便你看,在init方法里。
            http://pan.baidu.com/s/1jGGpPYI  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 14:00 戰(zhàn)魂小筑
            @phantom
            engine.CallVoidScript("script_MemBufferWrite",pBuff,(void*)&size,sizeof(int));

            你的(void*)&size想表達什么意思? 穿大小就把size傳進去, lua不支持指針!  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 14:06 phantom
            @戰(zhàn)魂小筑
            因為那是個數(shù)據(jù)起始地址,我就隨便往buffer里寫4個字節(jié)數(shù)據(jù),就所以就隨便取了一個size變量的地址,傳進去size的大小。假設(shè)我在lua里調(diào),buffer:Write("Hello,World!",12)也會崩。這正常嗎?  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 14:07 戰(zhàn)魂小筑
            @phantom
            lua不能這么玩, 你先查下資料吧, 腳本沒指針, 無法操作內(nèi)存,只有常用類型  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 14:27 phantom
            果然是這樣,我又加了個不帶指針的多參方法,沒有此問題了,我去補一下lua相關(guān)知識。非常感謝~  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-11-05 17:52 hcaihao
            LuaBridge不支持下面特性:
            枚舉型常量
            不支持8個以上的函數(shù)或方法的調(diào)用
            重載函數(shù)、方法和構(gòu)造函數(shù)(Overloaded functions, methods, or constructors)
            全局變量(變量必須被包裝在命名空間里)
            自動地轉(zhuǎn)換STL容器類型和Table
            在Lua中繼承C++類(Inheriting Lua classes from C++ classes)。
            Passing nil to a C++ function that expects a pointer or reference
            Standard containers like std::shared_ptr   回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-12-03 15:25 super_huai
            @戰(zhàn)魂小筑
            試用了一下,感覺不錯。但是有wchar_t* 參數(shù)的函數(shù)一直注冊不上,不知道什么原因
            void foo( const wchar_t* str )
            {
            }
            luabridge::getGlobalNamespace(L).addFunction("foo", foo );

            lua側(cè)的代碼

            foo("123"); //崩潰了

            不知道有什么方法可以解決?  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-12-03 15:26 戰(zhàn)魂小筑
            @super_huai
            除非你注定主做windows, 否則還是全用char+utf8吧
            wchar的東西很煩的  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-12-03 16:03 super_huai
            @戰(zhàn)魂小筑
            感謝回復(fù)
            看了luaBridge的說明,是可以做到支持的
            ## The Lua Stack

            In the Lua C API, all operations on the `lua_State` are performed through the
            Lua stack. In order to pass parameters back and forth between C++ and Lua,
            LuaBridge uses specializations of this template class concept:

            template <class T>
            struct Stack
            {
            static void push (lua_State* L, T t);
            static T get (lua_State* L, int index);
            };

            The Stack template class specializations are used automatically for variables,
            properties, data members, property members, function arguments and return
            values. These basic types are supported:

            - `bool`
            - `char`, converted to a string of length one.
            - `char const*` and `std::string` strings.
            - Integers, `float`, and `double`, converted to `Lua_number`.

            User-defined types which are convertible to one of the basic types are
            possible, simply provide a `Stack <>` specialization in the `luabridge`
            namespace for your user-defined type, modeled after the existing types.
            For example, here is a specialization for a [juce::String][6]:

            template <>
            struct Stack <juce::String>
            {
            static void push (lua_State* L, juce::String s)
            {
            lua_pushstring (L, s.toUTF8 ());
            }

            static juce::String get (lua_State* L, int index)
            {
            return juce::String (luaL_checkstring (L, index));
            }
            };  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-12-03 16:04 戰(zhàn)魂小筑
            @super_huai
            真心建議別這樣, 太慢了, 轉(zhuǎn)來轉(zhuǎn)去的  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-12-03 16:13 super_huai
            @戰(zhàn)魂小筑
            因為是從現(xiàn)有的庫做的,該庫操作的全是unicode,全部改造代價太大,所以不得不這么轉(zhuǎn)
            現(xiàn)在實現(xiàn)的方式如下
            c++
            int Utf8ToT(lua_State *L)
            {
            size_t n = 0;
            char* str = (char*)luaL_checklstring(L, -1, &n);
            if(!str) return 0;
            tstring strT=UTF82W(str);
            lua_pushlstring(L, (const char*)(LPCWSTR)strT.c_str(), (strT.size()+1)*sizeof(wchar_t));
            return 1;
            }

            luabridge::getGlobalNamespace(L)
            .addCFunction("A2T", Utf8ToT );

            luaL_dostring(L,"function T (str)\n return A2T(str);\nend");//注冊一個全局的"T"函數(shù),用來將utf8編碼的字符串轉(zhuǎn)換為TCHAR

            lua側(cè)的代碼

            foo(T"123");   回復(fù)  更多評論
              

            日韩久久久久中文字幕人妻 | 久久久老熟女一区二区三区| 亚洲精品美女久久久久99| 国产精品久久久久AV福利动漫| 久久99国产一区二区三区| 久久精品桃花综合| 日本久久久久久中文字幕| 亚洲国产精品无码久久九九| 久久精品免费一区二区三区| 久久久久青草线蕉综合超碰| 99久久久久| 91视频国产91久久久| 东方aⅴ免费观看久久av| 一级女性全黄久久生活片免费| 久久久久综合网久久| 成人久久免费网站| 色婷婷久久久SWAG精品| 91精品国产91热久久久久福利| 色综合久久久久综合体桃花网| 久久伊人中文无码| 久久精品国产一区二区电影| 狠狠干狠狠久久| 国产99精品久久| 久久久一本精品99久久精品66| 噜噜噜色噜噜噜久久| 久久久国产一区二区三区| 天天综合久久久网| 国产精品久久久久9999高清| 久久精品人人做人人妻人人玩| 久久精品国产99久久久古代| 97香蕉久久夜色精品国产| 三级韩国一区久久二区综合 | 国产午夜精品理论片久久影视 | 欧美激情精品久久久久| 麻豆成人久久精品二区三区免费| 精产国品久久一二三产区区别 | 久久久久人妻一区二区三区vr| 国产aⅴ激情无码久久| 亚洲欧美日韩久久精品第一区| 久久无码专区国产精品发布| 久久亚洲AV成人无码|