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

            以下代碼使用luabind進(jìn)行l(wèi)ua的coroutine測(cè)試

               1: void ScriptManagedChannel::OnServiceInitialize()
               2: {    
               3:     try
               4:     {        
               5:         mThread = lua_newthread( GScriptScriptContext->GetVM() );
               6:  
               7:         luabind::resume_function<void>( mThread, "ScriptMain", this );
               8:  
               9:         Resume();
              10:     }
              11:     catch (std::exception& e)
              12:     {
              13:         const char* ErrorMsg = lua_tostring( GScriptScriptContext->GetVM(), -1 );            
              14:         printf("%s\n", e.what() );
              15:     }
              16:  
              17:     
              18: }
              19:  
              20: void ScriptManagedChannel::Resume( )
              21: {
              22:     luabind::resume<void>( mThread );
              23: }
              24:  
              25: void ScriptManagedChannel::StopTest( )
              26: {
              27:     lua_yield( mThread, 0 );
              28: }
              29:  
              30:  

            代碼中, mThread類型為lua_State*類型

            GScriptScriptContext->GetVM()是加載了代碼的lua_State*

            StopTest為注冊(cè)為ScriptManagedChannel類成員函數(shù)到lua中的定義

            接下來(lái)看lua端的測(cè)試代碼:

               1: function ScriptMain( Channel )
               2:  
               3:     
               4:     for i = 1, 5 do
               5:     
               6:     print("done", i)
               7:     
               8:     Channel:StopTest( )
               9:     
              10:     
              11:     
              12:     end
              13: end

            剛開(kāi)始,在測(cè)試代碼時(shí), lua中有個(gè)手誤而造成的錯(cuò)誤, 導(dǎo)致C++代碼運(yùn)行到第7行時(shí)彈出assert

            位于:luabind-0.9.1\luabind\detail\call_function.hpp 第264行,對(duì)應(yīng)以下代碼第13行

               1: ~proxy_function_void_caller()
               2: {
               3:     if (m_called) return;
               4:  
               5:     m_called = true;
               6:     lua_State* L = m_state;
               7:  
               8:     int top = lua_gettop(L);
               9:  
              10:     push_args_from_tuple<1>::apply(L, m_args);
              11:     if (m_fun(L, boost::tuples::length<Tuple>::value, 0))
              12:     {
              13:         assert(lua_gettop(L) == top - m_params + 1);
              14:  
              15: NO_EXCEPTIONS
              16:         throw luabind::error(L);
              17: #else
              18:         error_callback_fun e = get_error_callback();
              19:         if (e) e(L);
              20:     
              21:         assert(0 && "the lua function threw an error and exceptions are disabled."
              22:                 " If you want to handle the error you can use luabind::set_error_callback()");
              23:         std::terminate();
              24: #endif
              25:     }
              26:     // pops the return values from the function call
              27:     stack_pop pop(L, lua_gettop(L) - top + m_params);
              28: }

            11行代碼中調(diào)用的是lua_resume, 返回的是運(yùn)行錯(cuò)誤, 但是被13行的assert擋住了, 無(wú)法通過(guò)第16行拋出異常被外面捕獲.

            因此,嘗試注釋第13行, 再測(cè)試, 可以在lua拋出錯(cuò)誤后, 在棧頂捕獲到coroutine函數(shù)resume時(shí)報(bào)出的錯(cuò)誤信息.問(wèn)題解決

             

            對(duì)于lua的coroutine, 網(wǎng)上資料不多, 這里有一篇比較詳細(xì)的代碼

            我比較疑惑的是, 有沒(méi)有必要將代碼在dofile或者dobuffer時(shí), 必須傳入newthread出的state? 如果還是傳入原始的state會(huì)有什么影響?

            歡迎各位有此經(jīng)驗(yàn)的討論

            posted on 2012-03-27 10:38 戰(zhàn)魂小筑 閱讀(1527) 評(píng)論(2)  編輯 收藏 引用 所屬分類: 腳本技術(shù)C++/ 編程語(yǔ)言

            評(píng)論

            # re: luabind使用coroutine時(shí)的一處善意提示導(dǎo)致的BUG[未登錄](méi) 2012-03-27 15:36 陳梓瀚(vczh)
            assert和exception是不一樣的。assert是絕對(duì)不能發(fā)生的錯(cuò)誤,exception只是用來(lái)替換類似HRESULT這種COM的返回值而已。發(fā)生了assert則一定要修改代碼使之不發(fā)生(對(duì)于你的情況就是修改你傳入的參數(shù)),而exception你可以處理或者不處理。

            所以這個(gè)不是lua的問(wèn)題,是你的問(wèn)題。  回復(fù)  更多評(píng)論
              

            # re: luabind使用coroutine時(shí)的一處善意提示導(dǎo)致的BUG 2012-03-27 17:30 戰(zhàn)魂小筑
            @陳梓瀚(vczh)
            大哥,我說(shuō)了嘛,故意錯(cuò)誤而導(dǎo)致的, 把a(bǔ)ssert跳過(guò)就能正確拋出代碼中錯(cuò)誤信息
            如果代碼正確,壓根不會(huì)有assert  回復(fù)  更多評(píng)論
              

            久久人人爽人人爽人人AV| 99久久无码一区人妻| 国产精品久久久久久久久| 99久久国产亚洲高清观看2024 | 日韩人妻无码一区二区三区久久99| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区| 久久久亚洲裙底偷窥综合| 94久久国产乱子伦精品免费| 人妻无码αv中文字幕久久琪琪布 人妻无码精品久久亚瑟影视 | 国产精品久久久久久影院 | 久久久久亚洲精品日久生情| 97久久久精品综合88久久| 91麻豆国产精品91久久久| 国产精品成人无码久久久久久 | 伊人丁香狠狠色综合久久| 久久久久久久久久久| 久久99精品久久久久久水蜜桃| 蜜臀av性久久久久蜜臀aⅴ麻豆| 久久免费视频一区| 久久99国产精品久久久| 久久男人Av资源网站无码软件| 精品欧美一区二区三区久久久| 99久久99久久久精品齐齐| 中文无码久久精品| 伊人久久大香线蕉无码麻豆| 国产精品内射久久久久欢欢| 久久99精品国产麻豆宅宅 | 久久婷婷人人澡人人| 国产精品成人99久久久久91gav| 久久99精品久久久久久久久久| 久久www免费人成看片| 亚洲欧美成人久久综合中文网| 久久精品无码av| 九九热久久免费视频| 久久精品国产亚洲精品| 久久精品国产99久久香蕉| 国产呻吟久久久久久久92| 国产99久久久国产精免费| 精品水蜜桃久久久久久久| 精品免费久久久久国产一区| 久久久91人妻无码精品蜜桃HD|