diff --git a/src/scope_info.cpp b/src/scope_info.cpp index 5f799bd141..3008c5226a 100644 --- a/src/scope_info.cpp +++ b/src/scope_info.cpp @@ -24,7 +24,7 @@ #ifdef USE_SCOPE_INFO -std::vector> _scope_stack; +std::vector _scope_stack; int WriteScopeLog(char *buf, const char *last) { @@ -34,7 +34,7 @@ int WriteScopeLog(char *buf, const char *last) int depth = 0; for (auto it = _scope_stack.rbegin(); it != _scope_stack.rend(); ++it, depth++) { b += seprintf(b, last, "\n %2d: ", depth); - b += (*it)(b, last); + b += it->functor(it->target, b, last); } b += seprintf(b, last, "\n\n"); } diff --git a/src/scope_info.h b/src/scope_info.h index 40ccc69b60..3380f1cbdd 100644 --- a/src/scope_info.h +++ b/src/scope_info.h @@ -12,7 +12,6 @@ #include "tile_type.h" -#include #include struct Vehicle; @@ -21,12 +20,19 @@ struct Window; #ifdef USE_SCOPE_INFO -extern std::vector> _scope_stack; +struct ScopeStackRecord { + using ScopeStackFunctor = int (*)(void *, char *, const char *); + + ScopeStackFunctor functor; + void *target; +}; + +extern std::vector _scope_stack; struct scope_info_func_obj { - scope_info_func_obj(std::function func) + scope_info_func_obj(ScopeStackRecord record) { - _scope_stack.emplace_back(std::move(func)); + _scope_stack.emplace_back(record); } scope_info_func_obj(const scope_info_func_obj ©src) = delete; @@ -43,16 +49,17 @@ int WriteScopeLog(char *buf, const char *last); /** * This creates a lambda in the current scope with the specified capture which outputs the given args as a format string. - * This lambda is then captured by reference in a std::function which is pushed onto the scope stack + * This lambda is then captured by pointer in a ScopeStackRecord which is pushed onto the scope stack * The scope stack is popped at the end of the scope */ #define SCOPE_INFO_FMT(capture, ...) \ auto SCOPE_INFO_PASTE(_sc_lm_, __LINE__) = capture (char *buf, const char *last) { \ return seprintf(buf, last, __VA_ARGS__); \ }; \ - scope_info_func_obj SCOPE_INFO_PASTE(_sc_obj_, __LINE__) ([&](char *buf, const char *last) -> int { \ - return SCOPE_INFO_PASTE(_sc_lm_, __LINE__) (buf, last); \ - }); + scope_info_func_obj SCOPE_INFO_PASTE(_sc_obj_, __LINE__) (ScopeStackRecord{ [](void *target, char *buf, const char *last) -> int { \ + auto targ = static_cast(target); \ + return (*targ)(buf, last); \ + }, static_cast(& SCOPE_INFO_PASTE(_sc_lm_, __LINE__)) }); #else /* USE_SCOPE_INFO */