<commit_before>local safe_region_callback
local safe_region_name
local safe_region_param

check_region = function(name, param)
	--obtain positions
	local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
	if pos1 == nil or pos2 == nil then
		worldedit.player_notify(name, "no region selected")
		return nil
	end

	return worldedit.volume(pos1, pos2)
end

--`callback` is a callback to run when the user confirms
--`nodes_needed` is a function accepting `param`, `pos1`, and `pos2` to calculate the number of nodes needed
safe_region = function(callback, nodes_needed)
	--default node volume calculation
	nodes_needed = nodes_needed or check_region

	return function(name, param)
		--check if the operation applies to a safe number of nodes
		local count = nodes_needed(name, param)
		if count == nil then return end --invalid command
		if count < 10000 then
			return callback(name, param)
		end

		--save callback to call later
		safe_region_callback, safe_region_name, safe_region_param = callback, name, param
		worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel")
	end
end

minetest.register_chatcommand("/y", {
	params = "",
	description = "Confirm a pending operation",
	func = function()
		local callback, name, param = safe_region_callback, safe_region_name, safe_region_param
		if not callback then
			worldedit.player_notify(name, "no operation pending")
			return
		end

		--obtain positions
		local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
		if pos1 == nil or pos2 == nil then
			worldedit.player_notify(name, "no region selected")
			return
		end

		safe_region_callback, safe_region_name, safe_region_param = nil, nil, nil --reset pending operation
		callback(name, param, pos1, pos2)
	end,
})

minetest.register_chatcommand("/n", {
	params = "",
	description = "Confirm a pending operation",
	func = function()
		if not safe_region_callback then 
			worldedit.player_notify(name, "no operation pending")
			return
		end
		safe_region_callback, safe_region_name, safe_region_param = nil, nil, nil
	end,
})
<commit_msg>Fix safe region functionality (thanks ChaosWormz).<commit_after>local safe_region_callback = {}
local safe_region_param = {}

check_region = function(name, param)
	local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] --obtain positions
	if pos1 == nil or pos2 == nil then
		worldedit.player_notify(name, "no region selected")
		return nil
	end
	return worldedit.volume(pos1, pos2)
end

--`callback` is a callback to run when the user confirms
--`nodes_needed` is a function accepting `param`, `pos1`, and `pos2` to calculate the number of nodes needed
safe_region = function(callback, nodes_needed)
	--default node volume calculation
	nodes_needed = nodes_needed or check_region

	return function(name, param)
		--check if the operation applies to a safe number of nodes
		local count = nodes_needed(name, param)
		if count == nil then return end --invalid command
		if count < 10000 then
			return callback(name, param)
		end

		--save callback to call later
		safe_region_callback[name], safe_region_param[name] = callback, param
		worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel")
	end
end

minetest.register_chatcommand("/y", {
	params = "",
	description = "Confirm a pending operation",
	func = function(name)
		local callback, param = safe_region_callback[name], safe_region_param[name]
		if not callback then
			worldedit.player_notify(name, "no operation pending")
			return
		end

		--obtain positions
		local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
		if pos1 == nil or pos2 == nil then
			worldedit.player_notify(name, "no region selected")
			return
		end

		safe_region_callback[name], safe_region_param[name] = nil, nil --reset pending operation
		callback(name, param, pos1, pos2)
	end,
})

minetest.register_chatcommand("/n", {
	params = "",
	description = "Confirm a pending operation",
	func = function(name)
		if not safe_region_callback[name] then
			worldedit.player_notify(name, "no operation pending")
			return
		end
		safe_region_callback[name], safe_region_param[name] = nil, nil
	end,
})

{'fraction_non_alphanumeric': 0.09258416742493175, 'fraction_numerical': 0.010464058234758872, 'mean_word_length': 3.8693244739756367, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1852310', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1311, 'n_words': 439}