Skip to content

Commit

Permalink
Fix set_bone_position regression (error on passing none)
Browse files Browse the repository at this point in the history
  • Loading branch information
appgurueu committed Dec 21, 2023
1 parent cb38b84 commit cad8e89
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
13 changes: 9 additions & 4 deletions src/script/common/c_internal.cpp
Expand Up @@ -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) + ":"
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/script/common/c_internal.h
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/script/lua_api/l_object.cpp
Expand Up @@ -520,20 +520,20 @@ 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);
if (sao == nullptr)
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;
Expand All @@ -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);
Expand Down

0 comments on commit cad8e89

Please sign in to comment.