My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 233 attachment: DebugStdio.hx (3.1 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package hxcpp;

import haxe.CallStack;
import cpp.vm.Debugger;
import hxcpp.DebugBase;
import Type;


class DebugStdio extends DebugBase
{
var input:haxe.io.Input;

public function new(inCreateStopped:Bool=false)
{
super(inCreateStopped);
}

override function init():Bool
{
input = Sys.stdin();
return true;
}

override function onCloseInput()
{
if (input!=null)
input.close();
}


override function getNextCommand() : String
{
Sys.print("debug>");
return input.readLine();
}


function sendOutput(inString:String)
{
Sys.println(inString);
}

function sendStatus(inString:String)
{
sendOutput(inString);
}

override function sendString(inString:String)
{
sendOutput(inString);
}

override function onRunning()
{
sendStatus("running");
}


override function onStopped()
{
sendStatus("stopped.");
}

override function showWhere()
{
var idx = 0;
for(item in stack)
{
idx++;
sendOutput((idx==frame ? "*" : " ") + idx + ":" + item);
}
}

override function showFiles()
{
if (files!=null)
for(idx in 0...files.length)
sendOutput("file " + idx + " : " + files[idx] );
}

override function showBreakpoints()
{
var bps = Debugger.getBreakpoints();
if (bps!=null)
for(idx in 0...bps.length)
sendOutput("breakpoint " + idx + " : " + bps[idx] );
}

function printRec(inPrefix:String, result:Dynamic, inLevel:Int)
{
if (result==null)
sendOutput(inPrefix + "(null)");
else if ( untyped result.__IsArray() )
{
var len = result.length;
var lim = len<arrayLimit ? len : arrayLimit;
if (lim==0)
sendOutput(inPrefix + "(empty)");
else if (inLevel>0)
sendOutput(inPrefix + len + " elements");
else
{
for(i in 0...lim)
printRec(inPrefix + i + "] ", result[i], inLevel+1);
if (lim<len)
sendOutput(inPrefix + "..." + len + "elements");
}
}
else switch Type.typeof(result)
{
case TObject:
sendObject(inPrefix,result,inLevel, "{...}");
case TClass(c):
if (c==String)
sendOutput(inPrefix+result);
else
sendObject(inPrefix,result,inLevel,c+"");
default:
sendOutput(inPrefix + result);
}
}

function sendObject(inPrefix:String,result:Dynamic,inLevel:Int, inClass:String)
{
if (inLevel>0)
sendOutput(inPrefix + inClass);
else
{
var fields = Reflect.fields(result);
if (files.length==0)
sendOutput(inPrefix + "{}");
else
for(field in fields)
{
printRec(inPrefix + field + "=", Reflect.getProperty(result,field), inLevel+1 );
}
}
}


override function onPrint(result:Dynamic)
{
printRec("",result,0);
}

override function onResult(inResult:String)
{
sendOutput(inResult);
}


}


Powered by Google Project Hosting