Page 1 of 1

DebugStructure() Macro

Posted: Thu Oct 24, 2019 7:20 am
by infratec
Since it is easier to find I create an own topic here.

Code: Select all

EnableExplicit

Macro DebugStructure(variable_, structure_)
 
  CompilerIf #PB_Compiler_Debugger
   
    CompilerIf Not Defined(DebugStructure_JSON, #PB_Variable)
      Define DebugStructure_JSON.i
    CompilerEndIf
   
    DebugStructure_JSON = CreateJSON(#PB_Any)
    If DebugStructure_JSON
      InsertJSONStructure(JSONValue(DebugStructure_JSON), @variable_, structure_)
      Debug ComposeJSON(DebugStructure_JSON, #PB_JSON_PrettyPrint)
      FreeJSON(DebugStructure_JSON)
    EndIf
   
  CompilerEndIf
 
EndMacro


Structure test
  a.s
  b.f
  c.i
  d.d
  e.s
  f.i
EndStructure

Define t.test

t\a = "Test"
t\b = 1.1
t\c = 3
t\d = 1.2345678
t\e = "blabla"
t\f = 2

DebugStructure(t, test)

Re: DebugStructure() Macro

Posted: Thu Oct 24, 2019 9:47 am
by Kwai chang caine
Yes, really good idea :wink:
Thanks for sharing 8)

Re: DebugStructure() Macro

Posted: Thu Oct 24, 2019 12:15 pm
by Little John
Very cool, thanks for sharing!

I've added a link to this topic to my "Small tricks with JSON" thread.

Re: DebugStructure() Macro

Posted: Thu Oct 24, 2019 4:28 pm
by davido
@infratec,
Thank you for your clever macro.

@Little John,
Thank you for placing the code in your JSON repository.