MCPcopy Create free account
hub / github.com/DFHack/dfhack / get_from_lua_state

Function get_from_lua_state

library/include/DataFuncs.h:50–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 2

lua_writeMethod · 0.80
getFunction · 0.70

Tested by

no test coverage detected