| 48 | // will throw if lua code tries to pass a null pointer |
| 49 | template<typename T> requires std::is_reference_v<T> |
| 50 | T get_from_lua_state(lua_State* L, int idx) |
| 51 | { |
| 52 | using DFHack::LuaWrapper::field_error; |
| 53 | using DFHack::LuaWrapper::UPVAL_METHOD_NAME; |
| 54 | using Ptr = std::add_pointer_t<std::remove_reference_t<T>>; |
| 55 | Ptr ptr{}; |
| 56 | df::identity_traits<Ptr>::get()->lua_write(L, UPVAL_METHOD_NAME, &ptr, idx); |
| 57 | if (ptr == nullptr) |
| 58 | { |
| 59 | field_error(L, UPVAL_METHOD_NAME, "cannot convert null pointer to reference", "call"); |
| 60 | } |
| 61 | return *ptr; |
| 62 | } |
| 63 | |
| 64 | // handle call-by-value function arguments. only semi-regular types are allowed |
| 65 | // (semi-regular covers copyable and default-constructible) |