Skip to content

mutithread error handle #150

Description

@dogeFu

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 !

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions