Skip to content
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

stop/start inspection and direct print options #42

Closed
wants to merge 2 commits into from

Conversation

Sorky
Copy link

@Sorky Sorky commented Nov 6, 2018

Keep / discard / improve - Just sharing if you are interested...

  1. Allows the inspect to wait until needed
  2. Print (with user set text) rather than return

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...

  1. As shown in 'G' and 'K', all new options only need to exist and not be nil or false (ie: Can even be 1 or "")
  2. BONUS = Can start & stop inspection in one file from another!

PS...

Thanks for sharing the original!

Keep / discard / improve - Just sharing if you are interested...

  1. Allows the inspect to wait until needed
  2. Print (with user set text) rather than return

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...

  1. As shown in 'G' and 'K', all new options only need to exist and not be nil or false (ie: Can even be 1 or "")
  2. BONUS = Can start & stop inspection in one file from another!

PS...

  Thanks for sharing the original!
@coveralls
Copy link

coveralls commented Nov 6, 2018

Coverage Status

Coverage decreased (-1.8%) to 97.448% when pulling 307eb25 on Sorky:patch-1 into b611db6 on kikito:master.

@kikito
Copy link
Owner

kikito commented Sep 23, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants