1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Script: avoid fatal error in deprecated func handler

This commit is contained in:
SmallJoker 2025-04-23 21:41:18 +02:00 committed by GitHub
parent dd2e45ee82
commit d6d045aad4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -123,14 +123,18 @@ int ModApiBase::l_deprecated_function(lua_State *L, const char *good, const char
u64 start_time = porting::getTimeUs();
lua_Debug ar;
std::string backtrace;
// Get caller name with line and script backtrace
FATAL_ERROR_IF(!lua_getstack(L, 1, &ar), "lua_getstack() failed");
FATAL_ERROR_IF(!lua_getinfo(L, "Sl", &ar), "lua_getinfo() failed");
if (lua_getstack(L, 1, &ar) && lua_getinfo(L, "Sl", &ar)) {
// Get backtrace and hash it to reduce the warning flood
backtrace = ar.short_src;
backtrace.append(":").append(std::to_string(ar.currentline));
} else {
backtrace = "<tail call optimized coroutine> ";
backtrace.append(script_get_backtrace(L));
}
// Get backtrace and hash it to reduce the warning flood
std::string backtrace = ar.short_src;
backtrace.append(":").append(std::to_string(ar.currentline));
u64 hash = murmur_hash_64_ua(backtrace.data(), backtrace.length(), 0xBADBABE);
if (std::find(deprecated_logged.begin(), deprecated_logged.end(), hash)