| 12897 | } // namespace stack_detail |
| 12898 | |
| 12899 | inline int push_environment_of(lua_State* L, int index = -1) { |
| 12900 | #if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK |
| 12901 | luaL_checkstack(L, 1, detail::not_enough_stack_space_environment); |
| 12902 | #endif // make sure stack doesn't overflow |
| 12903 | #if SOL_LUA_VERSION < 502 |
| 12904 | // Use lua_getfenv |
| 12905 | lua_getfenv(L, index); |
| 12906 | #else |
| 12907 | // Use upvalues as explained in Lua 5.2 and beyond's manual |
| 12908 | if (lua_getupvalue(L, index, 1) == nullptr) { |
| 12909 | push(L, lua_nil); |
| 12910 | return 1; |
| 12911 | } |
| 12912 | #endif |
| 12913 | return 1; |
| 12914 | } |
| 12915 | |
| 12916 | template <typename T> |
| 12917 | int push_environment_of(const T& target) { |
no test coverage detected