Fix set_bone_position regression (error on passing none)

This commit is contained in:
Lars Müller 2023-12-21 18:55:12 +01:00 committed by GitHub
parent cb38b841af
commit cad8e895f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 10 deletions

@ -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);

@ -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)

@ -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<ObjectRef>(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<std::string>(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<ObjectRef>(L, 1);
ServerActiveObject *sao = getobject(ref);