Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mutithread error handle #150

Open
dogeFu opened this issue May 23, 2019 · 0 comments
Open

mutithread error handle #150

dogeFu opened this issue May 23, 2019 · 0 comments

Comments

@dogeFu
Copy link

dogeFu commented May 23, 2019

I set a lua function as a callback in C++.

In a child thread ,I call a "run_in_main_thread" function , to call this callback in main thread. (because
this callback can not be called in child thread ).

the problem is , when this callback cause some errors , the catch code In CppBindingModule.h doesn't trigger.

 struct CppBindMethodBase{
    static int call(lua_State* L)
     {
         try {
             assert(lua_isuserdata(L, lua_upvalueindex(1)));
             const FN& fn = *reinterpret_cast<const FN*>(lua_touserdata(L, lua_upvalueindex(1)));
            assert(fn);
            CppArgTuple<P...> args;
           CppArgTupleInput<P...>::get(L, IARG, args);
            int n = CppInvokeMethod<FN, R, typename CppArg<P\>::HolderType...>::push(L, fn, args);
            return n + CppArgTupleOutput<P...>::push(L, args);
         } catch (std::exception& e) {

            //!!!  when error accur, this catch code didnot run. !!!
            return luaL_error(L, e.what());

         }
     }
 }

e.g: my callback is:

function callback()
     error(1)
end

ps:

when I called this same callback in main thread ,the catch code worked.

Any idea why this happen? I am not familiar with these mutithread things between lua and C++,any detailed description is really appreciated !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant