DebugStructure() Macro

Share your advanced PureBasic knowledge/code with the community.
infratec
Always Here
Always Here
Posts: 6874
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

DebugStructure() Macro

Post 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)
Last edited by infratec on Thu Oct 24, 2019 10:26 am, edited 1 time in total.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: DebugStructure() Macro

Post by Kwai chang caine »

Yes, really good idea :wink:
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: DebugStructure() Macro

Post by Little John »

Very cool, thanks for sharing!

I've added a link to this topic to my "Small tricks with JSON" thread.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: DebugStructure() Macro

Post by davido »

@infratec,
Thank you for your clever macro.

@Little John,
Thank you for placing the code in your JSON repository.
DE AA EB
Post Reply