MCPcopy Create free account
hub / github.com/ThePhD/sol2 / get_as_upvalues_using_function

Function get_as_upvalues_using_function

include/sol/stack.hpp:125–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123
124 template <typename T>
125 inline std::pair<T, int> get_as_upvalues_using_function(lua_State* L, int function_index = -1) {
126 static const std::size_t data_t_count = (sizeof(T) + (sizeof(void*) - 1)) / sizeof(void*);
127 typedef std::array<void*, data_t_count> data_t;
128 function_index = lua_absindex(L, function_index);
129 int index = 0;
130 data_t voiddata { {} };
131 for (std::size_t d = 0; d < sizeof(T); d += sizeof(void*)) {
132 // first upvalue is nullptr to respect environment shenanigans
133 // So +2 instead of +1
134 const char* upvalue_name = lua_getupvalue(L, function_index, index + 2);
135 if (upvalue_name == nullptr) {
136 // We should freak out here...
137 break;
138 }
139 voiddata[index] = lua_touserdata(L, -1);
140 ++index;
141 }
142 lua_pop(L, index);
143 return std::pair<T, int>(*reinterpret_cast<T*>(static_cast<void*>(voiddata.data())), index);
144 }
145
146 template <bool checked, typename Handler, typename Fx, typename... Args>
147 static decltype(auto) eval(types<>, std::index_sequence<>, lua_State*, int, Handler&&, record&, Fx&& fx, Args&&... args) {

Callers

nothing calls this directly

Calls 2

lua_absindexFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected