• <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 開源項(xiàng)目:https://github.com/davyxu

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

             

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

            luabind

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

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

            tolua++

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

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

             

            LuaPlus

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

             

            luaBridge

            項(xiàng)目地址: https://github.com/vinniefalco/LuaBridge

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

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

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

            看下演示代碼:

            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 微妙的平衡
            這個(gè)不錯(cuò)  回復(fù)  更多評論
              

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

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

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

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

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

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

            # re: 超越luabind的luaBridge 2015-10-28 09:29 phantom
            我就是看你這個(gè)博客才用的luabridge,結(jié)果一試,這個(gè)問題太明顯,而且更妙的是,官方demo沒有一個(gè)超過2參的例子,不得不承認(rèn)這庫真是太傻逼了。  回復(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忘了打包給個(gè)github地址
            https://github.com/bhlzlx/graphics/blob/master/ow/owcmn/owcmn.h
            別外,我直接下載的luabridge最新版,有編譯錯(cuò)誤,pushstring的地方要改成pushlstring才編譯過去。
            所以我才好煩啊,寫個(gè)庫最基本的都有問題感覺,所以才來請教大神,有沒有遇到這樣的問題。  回復(fù)  更多評論
              

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

            代碼能否搞個(gè)直接可以編譯的, 給你看代碼比開源代碼都麻煩, 無法編譯  回復(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里,單獨(dú)測試一下這個(gè)write方法就好。  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 13:42 phantom
            我這是用codelite + gcc寫的,要不我做一個(gè)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想表達(dá)什么意思? 穿大小就把size傳進(jìn)去, lua不支持指針!  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-10-28 14:06 phantom
            @戰(zhàn)魂小筑
            因?yàn)槟鞘莻€(gè)數(shù)據(jù)起始地址,我就隨便往buffer里寫4個(gè)字節(jié)數(shù)據(jù),就所以就隨便取了一個(gè)size變量的地址,傳進(jìn)去size的大小。假設(shè)我在lua里調(diào),buffer:Write("Hello,World!",12)也會(huì)崩。這正常嗎?  回復(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
            果然是這樣,我又加了個(gè)不帶指針的多參方法,沒有此問題了,我去補(bǔ)一下lua相關(guān)知識。非常感謝~  回復(fù)  更多評論
              

            # re: 超越luabind的luaBridge 2015-11-05 17:52 hcaihao
            LuaBridge不支持下面特性:
            枚舉型常量
            不支持8個(gè)以上的函數(shù)或方法的調(diào)用
            重載函數(shù)、方法和構(gòu)造函數(shù)(Overloaded functions, methods, or constructors)
            全局變量(變量必須被包裝在命名空間里)
            自動(dòng)地轉(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)魂小筑
            試用了一下,感覺不錯(cuò)。但是有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)魂小筑
            因?yàn)槭菑默F(xiàn)有的庫做的,該庫操作的全是unicode,全部改造代價(jià)太大,所以不得不這么轉(zhuǎn)
            現(xiàn)在實(shí)現(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");//注冊一個(gè)全局的"T"函數(shù),用來將utf8編碼的字符串轉(zhuǎn)換為TCHAR

            lua側(cè)的代碼

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

            久久婷婷是五月综合色狠狠| 久久久久精品国产亚洲AV无码 | 亚洲精品无码专区久久久| 97精品国产97久久久久久免费| 久久久精品国产sm调教网站| 国产精品99久久久久久猫咪| 精品久久久中文字幕人妻| 青青青青久久精品国产h| 无码国内精品久久综合88| 91久久精一区二区三区大全| 色狠狠久久综合网| 欧美久久综合性欧美| 三上悠亚久久精品| 亚洲国产成人乱码精品女人久久久不卡 | 国产精品久久久久免费a∨| 国产精品18久久久久久vr | 久久精品国产亚洲av水果派| 91久久福利国产成人精品| 丁香色欲久久久久久综合网| 久久99精品久久久久久噜噜| 久久99国产综合精品女同| 一级做a爰片久久毛片免费陪| 久久久精品一区二区三区| 久久香综合精品久久伊人| 久久精品无码免费不卡| 久久综合丁香激情久久| 成人国内精品久久久久一区| 欧美亚洲国产精品久久| 亚洲国产成人久久笫一页| 国产精品日韩欧美久久综合| 嫩草影院久久国产精品| 国产精品久久久久久一区二区三区| 亚洲精品午夜国产va久久| 久久嫩草影院免费看夜色| 99国内精品久久久久久久| 97久久国产亚洲精品超碰热| 无码国内精品久久人妻| 国色天香久久久久久久小说| 99久久精品免费看国产一区二区三区 | 欧美性大战久久久久久| 久久国产免费直播|