| 8548 | } // namespace stack |
| 8549 | |
| 8550 | inline lua_State* main_thread(lua_State* L, lua_State* backup_if_unsupported = nullptr) { |
| 8551 | #if SOL_LUA_VERSION < 502 |
| 8552 | if (L == nullptr) |
| 8553 | return backup_if_unsupported; |
| 8554 | lua_getglobal(L, detail::default_main_thread_name()); |
| 8555 | auto pp = stack::pop_n(L, 1); |
| 8556 | if (type_of(L, -1) == type::thread) { |
| 8557 | return lua_tothread(L, -1); |
| 8558 | } |
| 8559 | return backup_if_unsupported; |
| 8560 | #else |
| 8561 | if (L == nullptr) |
| 8562 | return backup_if_unsupported; |
| 8563 | lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD); |
| 8564 | lua_State* Lmain = lua_tothread(L, -1); |
| 8565 | lua_pop(L, 1); |
| 8566 | return Lmain; |
| 8567 | #endif // Lua 5.2+ has the main thread unqualified_getter |
| 8568 | } |
| 8569 | |
| 8570 | namespace detail { |
| 8571 | struct global_tag { |
no test coverage detected