Skip to content

Commit 323d45d

Browse files
committed
- Changed argc and argv to be variables
1 parent acbf82f commit 323d45d

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

extra/testrunner.clv

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function runtest(file) {
6464
} else {
6565
status = "FAIL";
6666
++failed;
67-
67+
6868
io:println("\r[" + status + "] " + title + " - " + (ts2 - ts1) + " ms");
6969
}
7070

@@ -76,7 +76,7 @@ function runtest(file) {
7676
}
7777
}
7878

79-
if (sys:argc() == 1) {
79+
if (sys:argc == 1) {
8080
var test_dirs = file:glob("tests/*");
8181

8282
for (var dir in test_dirs) {
@@ -85,9 +85,9 @@ if (sys:argc() == 1) {
8585
files.each(runtest);
8686
}
8787
} else {
88-
var test_file = sys:argv(1);
88+
var test_file = sys:argv;
8989

90-
runtest(test_file);
90+
runtest(test_file[1]);
9191
}
9292

9393
if (passed > 0 || failed > 0) {

modules/std/getopt/module.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ namespace getopt {
1313

1414
static CLEVER_FUNCTION(getopt)
1515
{
16-
16+
if (!clever_static_check_args("as|a")) {
17+
return;
18+
}
1719
}
1820

1921
} // clever::modules::std::getopt

modules/std/sys/sys.cc

+23-30
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,6 @@ static CLEVER_FUNCTION(get_cwd)
8888
result->setStr(CSTRING(path ? path : ""));
8989
}
9090

91-
// argv(int n)
92-
// Get n-th argv value
93-
static CLEVER_FUNCTION(argv)
94-
{
95-
if (!clever_static_check_args("i")) {
96-
return;
97-
}
98-
99-
if (args[0]->getInt() >= *g_clever_argc) {
100-
result->setBool(false);
101-
} else {
102-
result->setStr(new StrObject((*g_clever_argv)[args[0]->getInt()]));
103-
}
104-
}
105-
106-
// argc()
107-
// Get argc value
108-
static CLEVER_FUNCTION(argc)
109-
{
110-
if (!clever_static_check_no_args()) {
111-
return;
112-
}
113-
114-
result->setInt(*g_clever_argc);
115-
}
116-
11791
// sleep(int time)
11892
// Sleep for 'time' milliseconds
11993
static CLEVER_FUNCTION(sleep)
@@ -274,7 +248,7 @@ static CLEVER_FUNCTION(info)
274248
}
275249

276250
// Returns a Value ptr containing the OS name
277-
static Value* _get_os()
251+
static Value* get_os()
278252
{
279253
Value* val = new Value(CLEVER_STR_TYPE, true);
280254

@@ -288,6 +262,25 @@ static Value* _get_os()
288262
return val;
289263
}
290264

265+
// Returns a constant array containing the argv
266+
static Value* get_argv()
267+
{
268+
Value* argv = new Value();
269+
::std::vector<Value*> args;
270+
271+
for (int i = 0; i < *g_clever_argc; ++i) {
272+
args.push_back(new Value());
273+
args.back()->setStr((*g_clever_argv)[i]);
274+
args.back()->setConst(true);
275+
}
276+
277+
ArrayObject* arr = new ArrayObject(args);
278+
argv->setConst(true);
279+
argv->setObj(CLEVER_ARRAY_TYPE, arr);
280+
281+
return argv;
282+
}
283+
291284
} // clever::modules::std::sys
292285

293286
// Initializes Standard module
@@ -301,16 +294,16 @@ CLEVER_MODULE_INIT(SYSModule)
301294
addFunction(new Function("get_ppid", &CLEVER_NS_FNAME(sys, get_ppid)));
302295
addFunction(new Function("get_uid", &CLEVER_NS_FNAME(sys, get_uid)));
303296
addFunction(new Function("get_sid", &CLEVER_NS_FNAME(sys, get_sid)));
304-
addFunction(new Function("argc", &CLEVER_NS_FNAME(sys, argc)));
305-
addFunction(new Function("argv", &CLEVER_NS_FNAME(sys, argv)));
306297
addFunction(new Function("sleep", &CLEVER_NS_FNAME(sys, sleep)));
307298
addFunction(new Function("clock", &CLEVER_NS_FNAME(sys, clock)));
308299
addFunction(new Function("time", &CLEVER_NS_FNAME(sys, time)));
309300
addFunction(new Function("microtime", &CLEVER_NS_FNAME(sys, microtime)));
310301
addFunction(new Function("info", &CLEVER_NS_FNAME(sys, info)));
311302
addFunction(new Function("exit", &CLEVER_NS_FNAME(sys, exit)));
312303

313-
addVariable("OS", sys::_get_os());
304+
addVariable("OS", sys::get_os());
305+
addVariable("argc", new Value(long(*g_clever_argc), true));
306+
addVariable("argv", sys::get_argv());
314307
}
315308

316309
}}} // clever::modules::std

0 commit comments

Comments
 (0)