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

Method call

include/sol/protected_function.hpp:222–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220
221 template <typename... Ret, typename... Args>
222 decltype(auto) call(Args&&... args) const {
223 if constexpr (!Aligned) {
224 // we do not expect the function to already be on the stack: push it
225 if (m_error_handler.valid(lua_state())) {
226 detail::protected_handler<true, handler_t> h(lua_state(), m_error_handler);
227 base_t::push();
228 int pushcount = stack::multi_push_reference(lua_state(), std::forward<Args>(args)...);
229 return invoke(types<Ret...>(), std::make_index_sequence<sizeof...(Ret)>(), pushcount, h);
230 }
231 else {
232 detail::protected_handler<false, handler_t> h(lua_state(), m_error_handler);
233 base_t::push();
234 int pushcount = stack::multi_push_reference(lua_state(), std::forward<Args>(args)...);
235 return invoke(types<Ret...>(), std::make_index_sequence<sizeof...(Ret)>(), pushcount, h);
236 }
237 }
238 else {
239 // the function is already on the stack at the right location
240 if (m_error_handler.valid()) {
241 // the handler will be pushed onto the stack manually,
242 // since it's not already on the stack this means we need to push our own
243 // function on the stack too and swap things to be in-place
244 if constexpr (!is_stack_handler_v) {
245 // so, we need to remove the function at the top and then dump the handler out ourselves
246 base_t::push();
247 }
248 detail::protected_handler<true, handler_t> h(lua_state(), m_error_handler);
249 if constexpr (!is_stack_handler_v) {
250 lua_replace(lua_state(), -3);
251 h.stack_index = lua_absindex(lua_state(), -2);
252 }
253 int pushcount = stack::multi_push_reference(lua_state(), std::forward<Args>(args)...);
254 return invoke(types<Ret...>(), std::make_index_sequence<sizeof...(Ret)>(), pushcount, h);
255 }
256 else {
257 detail::protected_handler<false, handler_t> h(lua_state(), m_error_handler);
258 int pushcount = stack::multi_push_reference(lua_state(), std::forward<Args>(args)...);
259 return invoke(types<Ret...>(), std::make_index_sequence<sizeof...(Ret)>(), pushcount, h);
260 }
261 }
262 }
263
264 ~basic_protected_function() {
265 if constexpr (is_stateless_lua_reference_v<handler_t>) {

Callers

nothing calls this directly

Calls 5

pushFunction · 0.85
multi_push_referenceFunction · 0.85
invokeFunction · 0.85
lua_absindexFunction · 0.85
validMethod · 0.45

Tested by

no test coverage detected