From cad8e895f24c74d4cf329594e7069797f8480602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Thu, 21 Dec 2023 18:55:12 +0100 Subject: [PATCH] Fix set_bone_position regression (error on passing none) --- src/script/common/c_internal.cpp | 13 +++++++++---- src/script/common/c_internal.h | 3 ++- src/script/lua_api/l_object.cpp | 10 +++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp index b02591f3ac6c..1ca9f37678e5 100644 --- a/src/script/common/c_internal.cpp +++ b/src/script/common/c_internal.cpp @@ -124,8 +124,10 @@ void script_error(lua_State *L, int pcall_result, const char *mod, const char *f static void script_log_add_source(lua_State *L, std::string &message, int stack_depth) { - lua_Debug ar; + if (stack_depth <= 0) + return; + lua_Debug ar; if (lua_getstack(L, stack_depth, &ar)) { FATAL_ERROR_IF(!lua_getinfo(L, "Sl", &ar), "lua_getinfo() failed"); message.append(" (at " + std::string(ar.short_src) + ":" @@ -172,15 +174,18 @@ DeprecatedHandlingMode get_deprecated_handling_mode() return ret; } -void log_deprecated(lua_State *L, std::string message, int stack_depth) +void log_deprecated(lua_State *L, std::string message, int stack_depth, bool once) { DeprecatedHandlingMode mode = get_deprecated_handling_mode(); if (mode == DeprecatedHandlingMode::Ignore) return; - if (stack_depth >= 0) + if (once) { + script_log_unique(L, message, warningstream, stack_depth); + } else { script_log_add_source(L, message, stack_depth); - warningstream << message << std::endl; + warningstream << message << std::endl; + } if (mode == DeprecatedHandlingMode::Error) script_error(L, LUA_ERRRUN, NULL, NULL); diff --git a/src/script/common/c_internal.h b/src/script/common/c_internal.h index eac492d08108..78ce48e7ee6a 100644 --- a/src/script/common/c_internal.h +++ b/src/script/common/c_internal.h @@ -149,8 +149,9 @@ DeprecatedHandlingMode get_deprecated_handling_mode(); * @param message The deprecation method * @param stack_depth How far on the stack to the first user function * (ie: not builtin or core). -1 to disabled. + * @param once Log the deprecation warning only once per callsite. */ -void log_deprecated(lua_State *L, std::string message, int stack_depth = 1); +void log_deprecated(lua_State *L, std::string message, int stack_depth = 1, bool once = false); // Safely call string.dump on a function value // (does not pop, leaves one value on stack) diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index a0e8f69a5ad6..0221b257660d 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -520,7 +520,7 @@ int ObjectRef::l_set_bone_position(lua_State *L) { NO_MAP_LOCK_REQUIRED; - log_deprecated(L,"Deprecated call to set_bone_position, use set_bone_override instead"); + log_deprecated(L, "Deprecated call to set_bone_position, use set_bone_override instead", 1, true); ObjectRef *ref = checkObject(L, 1); ServerActiveObject *sao = getobject(ref); @@ -528,12 +528,12 @@ int ObjectRef::l_set_bone_position(lua_State *L) return 0; std::string bone; - if (!lua_isnil(L, 2)) + if (!lua_isnoneornil(L, 2)) bone = readParam(L, 2); BoneOverride props; - if (!lua_isnil(L, 3)) + if (!lua_isnoneornil(L, 3)) props.position.vector = check_v3f(L, 3); - if (!lua_isnil(L, 4)) + if (!lua_isnoneornil(L, 4)) props.rotation.next = core::quaternion(check_v3f(L, 4) * core::DEGTORAD); props.position.absolute = true; props.rotation.absolute = true; @@ -546,7 +546,7 @@ int ObjectRef::l_get_bone_position(lua_State *L) { NO_MAP_LOCK_REQUIRED; - log_deprecated(L,"Deprecated call to get_bone_position, use get_bone_override instead"); + log_deprecated(L, "Deprecated call to get_bone_position, use get_bone_override instead", 1, true); ObjectRef *ref = checkObject(L, 1); ServerActiveObject *sao = getobject(ref);