-
Notifications
You must be signed in to change notification settings - Fork 568
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
Get rid of recursive call in default.dig_up #3133
base: master
Are you sure you want to change the base?
Get rid of recursive call in default.dig_up #3133
Conversation
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.
works
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.
Works. Tested with print
in minetest.dig_up
while digging papyrus. Height limit works too.
Co-authored-by: SmallJoker <[email protected]>
minetest.log("error", "Error raised during `default.dig_up` call:") | ||
for line in debug.traceback(...):gmatch("([^\n]*)\n?") do | ||
minetest.log("error", line) | ||
end |
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.
As an alternative to manual parsing and outputting - might minetest.error_handler(...)
produce better output?
EDIT: This should work: local noerr, success = xpcall(function() bla bla end, minetest.error_handler)
and then use the returned values to decide whether or not to reset in_dig_up
.
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.
Weirdly, using minetest.error_handler
does not print anything about the error... IDK why.
for line in debug.traceback(...):gmatch("([^\n]*)\n?") do | ||
minetest.log("error", line) | ||
end | ||
end) |
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.
not sure if to call this clever or a hack but here's a cleaner suggestion:
local in_dig_up = {}
setmetatable(in_dig_up, {__mode = "k"})
function default.dig_up(pos, node, digger, max_height)
local sentinel = {}
if in_dig_up[sentinel] then return end
-- ...
in_dig_up[sentinel] = true
-- ..
-- no resetting needed
end
it's even re-entrant
what is going on here? -> https://www.lua.org/pil/17.html
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.
This is a beautiful hack.
Fixes #3075
This PR fixes the recursive calling of
default.dig_up
and adds a parameter for a maximum number of nodes searched.This PR is ready for review.