Closed Sorky closed 3 years ago
I think this feature is better implemented in your own custom inspect, like so:
local inspect = require "inspect"
local function my_inspect(t)
if stopped then
...
end
return inspect(t)
end
And then use my_inspect
instead of inspect
all thorough your project.
Thanks for sending the PR though, and apologies for not reviewing it sooner.
Keep / discard / improve - Just sharing if you are interested...
Test...
-- Variables local extensions = {"png", "bmp", {["jpg"] = 1, ["jpeg"] = 2}}
-- Code print(inspect(extensions)) -- "A" print(inspect(extensions, {wait = true})) -- "B" print("C: Inspecting 'extensions': " .. inspect(extensions)) -- "C" print(inspect(extensions, {start = true})) -- "D" print("E: Inspecting 'extensions': " .. inspect(extensions, {wait = true})) -- "E" inspect(extensions, {wait = true, doprint = "F: Inspecting 'extensions'..."}) -- "F" inspect(extensions, {wait = true, doprint = "" }) -- "G" inspect({},{stop = true}) -- "H" inspect( extensions, {wait = true, doprint = "I: This should not inspect"}) -- "I" for i=1,4 do -- "J" if i == 3 then inspect(,{start = 1}) else inspect(,{stop = 1}) end -- "K" inspect( extensions, {wait = true, doprint = "L: Inspecting 'extensions' (" .. i .. ")..." } ) -- "L" end
Output...
{ "png", "bmp", { jpeg = 2, jpg = 1 } } did not inspect - waiting for a start C: Inspecting 'extensions': { "png", "bmp", { jpeg = 2, jpg = 1 } } inspect enabled E: Inspecting 'extensions': { "png", "bmp", { jpeg = 2, jpg = 1 } } F: Inspecting 'extensions'... { "png", "bmp", { jpeg = 2, jpg = 1 } } { "png", "bmp", { jpeg = 2, jpg = 1 } } L: Inspecting 'extensions' (3)... { "png", "bmp", { jpeg = 2, jpg = 1 } }
Commentary...
A: Original way still works B: Will only work when called after a call with start=true [note: status message added when using the original way] C: Original way still works [only usage with wait enabled can get blocked] D: Enable all subsequent wait enabled calls [Does not inspect the element / bonus status message when using the original way] E: Basically the same as 'C' but it will now work because a start has been done [unlike 'B' which was blocke] F: Basically the same as 'E' but using the new doprint option G: Basically the same as 'E' but using the new doprint option with no preamble H: Stop further inspections [absolutely nothing prints as opposed to 'D'] I: Inspection blocked just like 'B' [but absolutely nothing prints unlike 'B'] J: One situation where the new options can really help follows... K: Start and stop selectively [using simplest option settings with absolutely nothing printing] L: Thanks to 'K' it only inspects the chosen instance [3] !!!
Notes...
PS...
Thanks for sharing the original!