New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add file and line to NodeDef field deprecation warning #6708
Add file and line to NodeDef field deprecation warning #6708
Conversation
4bf2094
to
4eb37f2
Compare
For some reason doing this results in Minetest printing out the wrong line function foo()
minetest.get_mapgen_params() -- should be this line
end
foo() -- this line is given Edit: this is present in master too??? |
src/script/common/c_internal.cpp
Outdated
return "error-badstack:0"; | ||
|
||
if (!lua_getinfo(L, "Sl", &ar)) | ||
return "error-badgetinfo:0"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my brain parses this as badget info
no but wouldn't <invalid>:0
suffice in as error value?
src/script/common/c_internal.cpp
Outdated
{ | ||
lua_Debug ar; | ||
|
||
if (!lua_getstack(L, 2 + offset, &ar)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there might be a case where you want the actual calling function, i propose 1 + offset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason your code uses 2 rather than 1 here? It prints out the wrong position as detailed above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since log_deprecated
is called by a wrapper function through core.log()
you'll want to get the function that called the wrapper, not the wrapper itself....
okay this turns out to be trickier as log_deprecated
is also called directly from C++ in some cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that explains it. I'll have to pass an offset into log_deprecated and default to 0, unfortunately
4eb37f2
to
26af74b
Compare
WARNING[Main]: Field dug_item: Deprecated; use 'drop' field (at ...netest/bin/../games/minetest_game/mods/default/nodes.lua:1668)
26af74b
to
ade7515
Compare
So, currently it'll say that there's a deprecation in |
if (!lua_getinfo(L, "Sl", &ar)) | ||
return "error-badgetinfo:0"; | ||
|
||
return std::string(ar.short_src) + ":" + std::to_string(ar.currentline); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use append operator instead of + to prevent multiple memory string copy
What should be done here? This PR fixes a crash when calling a deprecated field, however the location it gives may not be accurate. I'm not sure how to properly pass in the path to builtin to work out where in the stack the last entry before builtin. I could instead try and find This could be merged as-is, as it's still more accurate than the current code on master and doesn't crash |
if (!lua_getinfo(L, "Sl", &ar)) | ||
return "error-badgetinfo:0"; | ||
|
||
return std::string(ar.short_src) + ":" + std::to_string(ar.currentline); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use append function instead of "+"
@@ -132,7 +145,7 @@ void script_run_callbacks_f(lua_State *L, int nargs, | |||
lua_remove(L, error_handler); | |||
} | |||
|
|||
void log_deprecated(lua_State *L, const std::string &message) | |||
void log_deprecated(lua_State *L, const std::string &message, unsigned int offset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u32
WARNING[Main]: Field dug_item: Deprecated; use 'drop' field (at ...netest/bin/../games/minetest_game/mods/default/nodes.lua:1668)
Replaces #3957