8 #define assert(expr, ...) _assert(print_assertfailed_severe, expr, __VA_ARGS__) 9 #define devassert(...) MACRO_BEGIN if (autocvar_developer > 0) assert(__VA_ARGS__); MACRO_END 11 #define assert_once(expr, ...) \ 16 assert(expr, __VA_ARGS__); \ 20 #define devassert_once(...) MACRO_BEGIN if (autocvar_developer > 0) assert_once(__VA_ARGS__); MACRO_END 22 #define demand(expr, ...) _assert(print_assertfailed_fatal, expr, __VA_ARGS__) 23 #define devdemand(...) MACRO_BEGIN if (autocvar_developer > 0) demand(__VA_ARGS__); MACRO_END 25 #define _assert(f, expr, then) \ 34 #define ASSERT_LESS(name, var, const) noref int name[(const - var + 1)]; 38 string(
string,
string...) strcat1n = #53;
40 string(
string,
string...) strcat1n = #115;
46 #define __SOURCELOC__ (sprintf("^7%s^9(^9"__FILE__"^7:^9"STR(__LINE__)"^7)", __FUNC__)) 48 #define __SOURCELOC__ (sprintf("^7%s^9(^9%s^7:^9%s^7)", __FUNC__, __FILE__, STR(__LINE__))) 51 #define _LOG_HEADER(level) "^9[::^7"PROGNAME"^9::"level"^9] ", __SOURCELOC__ 52 #define _LOG(f, level, s) \ 54 if (autocvar_developer > 0) f(strcat1n(_LOG_HEADER(level), "\n")); \ 55 f(strcat1n("^7", s, "\n")); \ 58 #define LOG_FATAL(...) _LOG_FATAL(strcat1n(__VA_ARGS__)) 59 #define LOG_FATALF(...) _LOG_FATAL(sprintf(__VA_ARGS__)) 60 #define _LOG_FATAL(s) _LOG(error, "^1FATAL", s) 62 #define LOG_SEVERE(...) _LOG_SEVERE(strcat1n(__VA_ARGS__)) 63 #define LOG_SEVEREF(...) _LOG_SEVERE(sprintf(__VA_ARGS__)) 64 #define _LOG_SEVERE(s) _LOG(backtrace, "^1SEVERE", s) 66 #define LOG_WARN(...) _LOG_WARN(strcat1n(__VA_ARGS__)) 67 #define LOG_WARNF(...) _LOG_WARN(sprintf(__VA_ARGS__)) 68 #define _LOG_WARN(s) _LOG(print, "^3WARNING", s) 70 #define LOG_INFO(...) _LOG_INFO(strcat1n(__VA_ARGS__)) 71 #define LOG_INFOF(...) _LOG_INFO(sprintf(__VA_ARGS__)) 72 #define _LOG_INFO(s) \ 74 if (autocvar_developer > 1) dprint(strcat1n(_LOG_HEADER("^5INFO"), "\n")); \ 78 if (str2chr(__s, strlen(__s) - 1) != '\n') { print("\n"); } \ 81 #define LOG_TRACE(...) _LOG_TRACE(strcat1n(__VA_ARGS__)) 82 #define LOG_TRACEF(...) _LOG_TRACE(sprintf(__VA_ARGS__)) 83 #define _LOG_TRACE(s) _LOG(dprint, "^6TRACE", s) 85 #define LOG_DEBUG(...) _LOG_DEBUG(strcat1n(__VA_ARGS__)) 86 #define LOG_DEBUGF(...) _LOG_DEBUG(sprintf(__VA_ARGS__)) 87 #define _LOG_DEBUG(s) _LOG(dprint2, "^2DEBUG", s) 89 #define dprint2(msg) \ 91 if (autocvar_developer > 1) dprint(msg); \ 95 #define LOG_HELP(...) _LOG_HELP(strcat1n(__VA_ARGS__)) 96 #define LOG_HELPF(...) _LOG_HELP(sprintf(__VA_ARGS__)) 97 #define _LOG_HELP(s) print("^7", s, "\n") 100 #define _backtrace() builtin_remove(NULL) 105 #define backtrace(msg) \ 107 int dev = autocvar_developer; \ 108 bool war = autocvar_prvm_backtraceforwarnings; \ 109 cvar_set("developer", "1"); \ 110 cvar_set("prvm_backtraceforwarnings", "1"); \ 111 print("\n--- CUT HERE ---\n", msg); \ 113 print("\n--- CUT UNTIL HERE ---\n"); \ 114 cvar_set("developer", ftos(dev)); \ 115 cvar_set("prvm_backtraceforwarnings", ftos(war)); \ 121 LOG_SEVERE(
"assertion failed: `", expr,
"`\n");
127 LOG_FATAL(
"assertion failed: `", expr,
"`\n");
void print_assertfailed_severe(string expr)
void print_assertfailed_fatal(string expr)
string(string, string...) strcat1n
noref int autocvar_developer
noref bool autocvar_prvm_backtraceforwarnings