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

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

             

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

            luabind

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

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

            tolua++

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

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

             

            LuaPlus

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

             

            luaBridge

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

            手冊(cè): http://vinniefalco.com/LuaBridge/Manual.html

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

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

            看下演示代碼:

            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) 評(píng)論(24)  編輯 收藏 引用 所屬分類(lèi): 腳本技術(shù)C++/ 編程語(yǔ)言

            評(píng)論

            # re: 超越luabind的luaBridge[未登錄](méi) 2013-12-08 22:44 微妙的平衡
            這個(gè)不錯(cuò)  回復(fù)  更多評(píng)論
              

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

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

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

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

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

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

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

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

            # re: 超越luabind的luaBridge 2015-10-28 13:19 phantom
            @戰(zhàn)魂小筑
            謝謝你回復(fù)這么快,我傳到百度盤(pán)了,代碼很少
            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才編譯過(guò)去。
            所以我才好煩啊,寫(xiě)個(gè)庫(kù)最基本的都有問(wèn)題感覺(jué),所以才來(lái)請(qǐng)教大神,有沒(méi)有遇到這樣的問(wèn)題。  回復(fù)  更多評(píng)論
              

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

            代碼能否搞個(gè)直接可以編譯的, 給你看代碼比開(kāi)源代碼都麻煩, 無(wú)法編譯  回復(fù)  更多評(píng)論
              

            # re: 超越luabind的luaBridge 2015-10-28 13:36 phantom
            注冊(cè)的代碼在這
            .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ú)測(cè)試一下這個(gè)write方法就好。  回復(fù)  更多評(píng)論
              

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

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

            # 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ù)  更多評(píng)論
              

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

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

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

            # 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容器類(lèi)型和Table
            在Lua中繼承C++類(lèi)(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ù)  更多評(píng)論
              

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

            lua側(cè)的代碼

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

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

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

            # re: 超越luabind的luaBridge 2015-12-03 16:03 super_huai
            @戰(zhàn)魂小筑
            感謝回復(fù)
            看了luaBridge的說(shuō)明,是可以做到支持的
            ## 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ù)  更多評(píng)論
              

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

            # re: 超越luabind的luaBridge 2015-12-03 16:13 super_huai
            @戰(zhàn)魂小筑
            因?yàn)槭菑默F(xiàn)有的庫(kù)做的,該庫(kù)操作的全是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");//注冊(cè)一個(gè)全局的"T"函數(shù),用來(lái)將utf8編碼的字符串轉(zhuǎn)換為T(mén)CHAR

            lua側(cè)的代碼

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

            精品综合久久久久久98| 久久精品aⅴ无码中文字字幕不卡| 成人午夜精品无码区久久| 久久久久亚洲?V成人无码| .精品久久久麻豆国产精品| 欧美精品久久久久久久自慰| 亚洲欧洲久久久精品| 久久亚洲AV无码西西人体| 九九久久精品国产| 久久国产精品二国产精品| 欧美激情精品久久久久| 99久久人妻无码精品系列蜜桃| 久久婷婷国产剧情内射白浆 | 日日狠狠久久偷偷色综合0| 99久久精品这里只有精品| 亚洲午夜久久久精品影院| 久久九九青青国产精品| 精品一区二区久久久久久久网站| 国产亚洲色婷婷久久99精品| 无遮挡粉嫩小泬久久久久久久| 亚洲精品无码久久久久| 久久精品中文闷骚内射| 久久婷婷成人综合色综合| 精品永久久福利一区二区| jizzjizz国产精品久久| 日本免费久久久久久久网站| 国产精品久久久久一区二区三区| 久久国产视屏| 久久综合亚洲鲁鲁五月天| 色综合久久无码中文字幕| 97精品久久天干天天天按摩| 国内精品伊人久久久久| 久久99久久成人免费播放| 亚洲国产精品嫩草影院久久| 国产精品成人久久久| 日本久久久久亚洲中字幕| 国产成年无码久久久久毛片| 伊人丁香狠狠色综合久久| 欧美麻豆久久久久久中文| 国内精品人妻无码久久久影院导航 | 国内精品久久久久久中文字幕 |