FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ReoScript/Source/ReoScriptRunner/Program.cs at master · unvell/ReoScript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
unvell
/
ReoScript
Public
Notifications
You must be signed in to change notification settings
Fork
35
Star
109
Code
Issues
4
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
ReoScript
/
Source
/
ReoScriptRunner
/
Program.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
328 lines (285 loc) · 6.53 KB
Breadcrumbs
ReoScript
/
Source
/
ReoScriptRunner
/
Program.cs
Copy path
File metadata and controls
328 lines (285 loc) · 6.53 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/*****************************************************************************
*
* ReoScript - .NET Script Language Engine
*
* https://github.com/unvell/ReoScript
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
* PURPOSE.
*
* This software released under MIT license.
* Copyright (c) 2012-2019 Jingwood, unvell.com, all rights reserved.
*
****************************************************************************/
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Text
;
using
System
.
IO
;
using
unvell
.
ReoScript
.
Diagnostics
;
namespace
unvell
.
ReoScript
{
class
ConsoleRunnerProgram
{
static
void
Main
(
string
[
]
args
)
{
if
(
args
.
Length
==
0
)
{
Console
.
WriteLine
(
@"ReoScript(TM) Running Machine
Copyright(c) 2012-2019 Jingwood, All Rights Reserved.
Usage: ReoScript [options] [filename...]
Options:
-e <script> Execute script string directly
-exec <script> Same as -e
-workpath <p> Set working directory
-debug Enable debug mode
-console Enter interactive console after execution
-com Compile mode (not yet available)"
)
;
return
;
}
List
<
string
>
files
=
new
List
<
string
>
(
)
;
string
workPath
=
null
;
bool
debug
=
false
;
string
initScript
=
null
;
bool
consoleMode
=
false
;
bool
compileMode
=
false
;
try
{
for
(
int
i
=
0
;
i
<
args
.
Length
;
i
++
)
{
string
arg
=
args
[
i
]
;
if
(
arg
.
StartsWith
(
"-"
)
)
{
string
param
=
arg
.
Substring
(
1
)
;
switch
(
param
)
{
case
"workpath"
:
workPath
=
GetParameter
(
args
,
i
)
;
i
++
;
break
;
case
"debug"
:
debug
=
true
;
break
;
case
"e"
:
case
"exec"
:
initScript
=
GetParameter
(
args
,
i
)
;
i
++
;
break
;
case
"com"
:
compileMode
=
true
;
break
;
case
"console"
:
consoleMode
=
true
;
break
;
}
}
else
{
files
.
Add
(
arg
)
;
}
}
}
catch
(
Exception
ex
)
{
OutLn
(
ex
.
Message
)
;
return
;
}
List
<
FileInfo
>
sourceFiles
=
new
List
<
FileInfo
>
(
)
;
foreach
(
string
file
in
files
)
{
FileInfo
fi
=
new
FileInfo
(
string
.
IsNullOrEmpty
(
workPath
)
?
file
:
Path
.
Combine
(
workPath
,
file
)
)
;
if
(
!
fi
.
Exists
)
{
Console
.
WriteLine
(
"Resource not found: "
+
fi
.
FullName
)
;
}
else
{
sourceFiles
.
Add
(
fi
)
;
if
(
string
.
IsNullOrEmpty
(
workPath
)
)
{
workPath
=
fi
.
DirectoryName
;
}
}
}
if
(
string
.
IsNullOrEmpty
(
workPath
)
)
{
workPath
=
Environment
.
CurrentDirectory
;
}
// JIT compile mode placeholder — will be reimplemented for .NET 10
if
(
compileMode
)
{
Console
.
WriteLine
(
"Compile mode is not yet available in this version."
)
;
return
;
}
// create SRM
ScriptRunningMachine
srm
=
new
ScriptRunningMachine
(
CoreFeatures
.
FullFeatures
)
;
if
(
debug
)
{
new
ScriptDebugger
(
srm
)
;
}
// set to full work mode
srm
.
WorkMode
|=
MachineWorkMode
.
AllowImportTypeInScript
|
MachineWorkMode
.
AllowCLREventBind
|
MachineWorkMode
.
AllowDirectAccess
;
// change work path
srm
.
WorkPath
=
workPath
;
// add built-in output listener
srm
.
AddStdOutputListener
(
new
BuiltinConsoleOutputListener
(
)
)
;
// not finished yet!
//srm.SetGlobalVariable("File", new FileConstructorFunction());
try
{
foreach
(
FileInfo
file
in
sourceFiles
)
{
// load script file
srm
.
Run
(
file
)
;
}
if
(
!
string
.
IsNullOrEmpty
(
initScript
)
)
{
srm
.
Run
(
initScript
)
;
}
}
catch
(
ReoScriptException
ex
)
{
string
str
=
string
.
Empty
;
if
(
ex
.
ErrorObject
==
null
)
{
str
=
ex
.
ToString
(
)
;
}
else
if
(
ex
.
ErrorObject
is
ErrorObject
)
{
ErrorObject
e
=
(
ErrorObject
)
ex
.
ErrorObject
;
str
+=
"Error: "
+
e
.
GetFullErrorInfo
(
)
;
}
else
{
str
+=
Convert
.
ToString
(
ex
.
ErrorObject
)
;
}
Console
.
WriteLine
(
str
)
;
}
if
(
consoleMode
)
{
OutLn
(
"
\n
Ready.
\n
"
)
;
bool
isQuitRequired
=
false
;
while
(
!
isQuitRequired
)
{
Prompt
(
)
;
string
line
=
In
(
)
.
Trim
(
)
;
if
(
line
==
null
)
{
isQuitRequired
=
true
;
break
;
}
else
if
(
line
.
StartsWith
(
"."
)
)
{
srm
.
Load
(
line
.
Substring
(
1
,
line
.
Length
-
1
)
)
;
}
else
if
(
line
.
StartsWith
(
"/"
)
)
{
string
consoleCmd
=
line
.
Substring
(
1
)
;
switch
(
consoleCmd
)
{
case
"q"
:
case
"quit"
:
case
"exit"
:
isQuitRequired
=
true
;
break
;
case
"h"
:
case
"help"
:
Help
(
)
;
break
;
default
:
break
;
}
}
else
if
(
line
.
Equals
(
"?"
)
)
{
ObjectValue
obj
=
srm
.
DefaultContext
.
ThisObject
as
ObjectValue
;
if
(
obj
!=
null
)
OutLn
(
obj
.
DumpObject
(
)
)
;
}
else
if
(
line
.
StartsWith
(
"?"
)
)
{
string
expression
=
line
.
Substring
(
1
)
;
try
{
object
value
=
srm
.
CalcExpression
(
expression
)
;
if
(
value
is
ObjectValue
)
{
OutLn
(
(
(
ObjectValue
)
value
)
.
DumpObject
(
)
)
;
}
else
{
OutLn
(
ScriptRunningMachine
.
ConvertToString
(
value
)
)
;
}
}
catch
(
Exception
ex
)
{
OutLn
(
"error: "
+
ex
.
Message
)
;
}
}
else
if
(
line
.
Length
==
0
)
{
continue
;
}
else
{
try
{
srm
.
Run
(
line
)
;
}
catch
(
ReoScriptException
ex
)
{
Console
.
WriteLine
(
"error: "
+
ex
.
Message
+
"
\n
"
)
;
}
}
}
OutLn
(
"Bye."
)
;
}
}
private
static
string
GetParameter
(
string
[
]
args
,
int
i
)
{
if
(
args
.
Length
<=
i
+
1
||
args
[
i
+
1
]
.
StartsWith
(
"-"
)
)
{
throw
new
ArgumentException
(
"Missing option parameters: "
+
args
[
i
]
)
;
}
else
return
args
[
i
+
1
]
;
}
private
static
void
Help
(
)
{
OutLn
(
@"
ReoScript Console Help
/<system command> submit system command.
quit | q quit from console.
help | h show this topic.
?[experssion] calculate an expression and output result.
if the expression is null, list all varaibles
in current global object.
<statement>; run script statement.
"
)
;
}
private
static
void
Prompt
(
)
{
Out
(
">"
)
;
}
private
static
void
Out
(
string
msg
)
{
Console
.
Write
(
msg
)
;
}
private
static
void
OutLn
(
)
{
Console
.
WriteLine
(
)
;
}
private
static
void
OutLn
(
string
msg
)
{
Console
.
WriteLine
(
msg
)
;
}
private
static
string
In
(
)
{
return
Console
.
ReadLine
(
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL