| 2015 | |
| 2016 | template <typename... Args> |
| 2017 | Maybe<LuaDetail::LuaFunctionReturn> LuaEngine::resumeThread(int handleIndex, Args const&... args) { |
| 2018 | lua_checkstack(m_state, 1); |
| 2019 | |
| 2020 | pushHandle(m_state, handleIndex); |
| 2021 | lua_State* threadState = lua_tothread(m_state, -1); |
| 2022 | lua_pop(m_state, 1); |
| 2023 | |
| 2024 | if (lua_status(threadState) != LUA_YIELD && lua_gettop(threadState) == 0) { |
| 2025 | throw LuaException("cannot resume a dead or errored thread"); |
| 2026 | } |
| 2027 | |
| 2028 | size_t argSize = pushArguments(threadState, args...); |
| 2029 | incrementRecursionLevel(); |
| 2030 | int res = lua_resume(threadState, nullptr, argSize); |
| 2031 | decrementRecursionLevel(); |
| 2032 | if (res != LUA_OK && res != LUA_YIELD) { |
| 2033 | propagateErrorWithTraceback(threadState, m_state); |
| 2034 | handleError(m_state, res); |
| 2035 | } |
| 2036 | |
| 2037 | int returnValues = lua_gettop(threadState); |
| 2038 | if (returnValues == 0) { |
| 2039 | return LuaDetail::LuaFunctionReturn(); |
| 2040 | } else if (returnValues == 1) { |
| 2041 | return LuaDetail::LuaFunctionReturn(popLuaValue(threadState)); |
| 2042 | } else { |
| 2043 | LuaVariadic<LuaValue> ret(returnValues); |
| 2044 | for (int i = returnValues - 1; i >= 0; --i) |
| 2045 | ret[i] = popLuaValue(threadState); |
| 2046 | return LuaDetail::LuaFunctionReturn(std::move(ret)); |
| 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | template <typename T> |
| 2051 | void LuaEngine::registerUserDataType() { |
no test coverage detected