Debugging mit neuem Reflection Modul

Übersicht BlitzMax, BlitzMax NG Allgemein

Neue Antwort erstellen

Vertex

Betreff: Debugging mit neuem Reflection Modul

BeitragDi, Okt 02, 2007 17:11
Antworten mit Zitat
Benutzer-Profile anzeigen
Eine tolle Sache. Man hat nur eine Instanz und kann diese ohne Vorwissen der Klasse debuggen:
Code: [AUSKLAPPEN]
SuperStrict

Framework BRL.Blitz
Import BRL.Reflection

Local Button : TButton

Button = New TButton
Button.SetPosition(10.0, 20.0)
Button.SetSize(100.0, 200.0)
Button.SetOffset(5.0, 5.0)

DebugObject(Button)
DebugObject("TestString")

Type TGadget Abstract
   Field X        : Float
   Field Y        : Float
   Field Z        : Int = 0
   Field Enabled  : Int = True

   Method Update() Abstract
   Method Draw() Abstract

   Method SetPosition(X:Float, Y:Float)
      Self.X = X
      Self.Y = Y
   End Method

   Method GetPosition(X:Float Var, Y:Float Var)
      X = Self.X
      Y = Self.Y
   End Method

   Method SetZ(Z:Int)
      Self.Z = Z
   End Method

   Method GetZ:Int()
      Return Self.Z
   End Method

   Method SetEnable(Enabled:Int)
      If Enabled Then
         Self.Enabled = True
      Else
         Self.Enabled = False
      EndIf
   End Method

   Method GetEnabled:Int()
      Return Self.Enabled
   End Method

   Method Compare:Int(OtherObject:Object)
      Local Other:TGadget
      
      Other = TGadget(OtherObject)
      If Not Other Or Self.Z < Other.Z Then
         Return -1
      ElseIf Other.Z = Self.Z Then
         Return 0
      Else
         Return 1
      EndIf
   End Method
End Type

Type TButton Extends TGadget
   Const STATE_UNPRESSED : Int = 0, ..
         STATE_ACTIVE    : Int = 1, ..
         STATE_PRESSED   : Int = 2

   Field Width   : Float
   Field Height  : Float
   Field OffsetX : Float
   Field OffsetY : Float
   Field State   : Int = STATE_UNPRESSED

   Method SetSize(Width:Float, Height:Float)
      Self.Width  = Width
      Self.Height = Height
   End Method

   Method GetSize(Width:Float Var, Height:Float Var)
      Width  = Self.Width
      Height = Self.Height
   End Method

   Method SetOffset(X:Float, Y:Float)
      Self.OffsetX = X
      Self.OffsetY = Y
   End Method

   Method GetOffset(X:Float Var, Y:Float Var)
      X = Self.OffsetX
      Y = Self.OffsetY
   End Method

   Method Update()
      ' Do anything
   End Method

   Method Draw()
      ' Do anything
   End Method
End Type

Function DebugObject(Instance:Object)
   Local TypeId : TTypeId

   If Not Instance Then Throw("Null reference")
   
   TypeId = TTypeId.ForObject(Instance)
   If TypeId.Name() = "String" Then
      DebugLog("String = " + String(Instance))
   Else
      DebugType(Instance, TypeId)
   EndIf
End Function

Function DebugType(Instance:Object, TypeId : TTypeId)
   Local SuperId    : TTypeId, ..
         TypeField  : TField, ..
         TypeMethod : TMethod, ..
         Arguments  : TTypeId[], ..
         Argument   : TTypeId, ..
         Temp       : String

   Temp = TypeId.Name()
   SuperId = TypeId.SuperType()
   While SuperId
      Temp :+ " > " + SuperId.Name()
      SuperId = SuperId.SuperType()
   Wend
   DebugLog(Temp)
   DebugLog("{")

   For TypeField = EachIn TypeId.EnumFields()
      DebugLog("~tField " + TypeField.Name() + " : " + ..
                            TypeField.TypeId().Name() + " = " + ..
                            TypeField.GetString(Instance))
   Next
   DebugLog("")

   For TypeMethod = EachIn TypeID.EnumMethods()
      Temp = "Method " + TypeMethod.Name()

      Arguments = TypeMethod.ArgTypes()
      If Arguments Then
         Temp :+ "("
         For Argument = EachIn Arguments
            Temp :+ Argument.Name() + ", "
         Next
         Temp = Temp[..Temp.Length - 2] + ")"
      EndIf
      
      DebugLog("~t" + Temp)
   Next
   
   DebugLog("}")
End Function


Mich interessiert wie man mit ByteTypeId, ShortTypeId usw. umgeht.

mfg olli
vertex.dreamfall.at | GitHub

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group