diff options
author | Li Jin <dragon-fly@qq.com> | 2022-03-05 22:49:02 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-03-05 22:49:02 +0800 |
commit | 4ff6d54b09a216648a00f333042fcf32ca8c4b44 (patch) | |
tree | a6cae456fca94fc04cb1672d35ed6c2cc74c9275 | |
parent | f48e99462a9fac6b4e5ad1b823b78d263025970c (diff) | |
download | yuescript-4ff6d54b09a216648a00f333042fcf32ca8c4b44.tar.gz yuescript-4ff6d54b09a216648a00f333042fcf32ca8c4b44.tar.bz2 yuescript-4ff6d54b09a216648a00f333042fcf32ca8c4b44.zip |
add global "arg" for CLI arguments.
-rw-r--r-- | src/yue.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/yue.cpp b/src/yue.cpp index aa043f7..04b7099 100644 --- a/src/yue.cpp +++ b/src/yue.cpp | |||
@@ -312,6 +312,14 @@ int main(int narg, const char** args) { | |||
312 | return 1; | 312 | return 1; |
313 | } | 313 | } |
314 | std::string evalStr = args[i]; | 314 | std::string evalStr = args[i]; |
315 | lua_newtable(L); | ||
316 | i++; | ||
317 | for (int j = i, index = 1; j < narg; j++) { | ||
318 | lua_pushstring(L, args[j]); | ||
319 | lua_rawseti(L, -2, index); | ||
320 | index++; | ||
321 | } | ||
322 | lua_setglobal(L, "arg"); | ||
315 | std::ifstream input(evalStr, std::ios::in); | 323 | std::ifstream input(evalStr, std::ios::in); |
316 | if (input) { | 324 | if (input) { |
317 | auto ext = fs::path(evalStr).extension().string(); | 325 | auto ext = fs::path(evalStr).extension().string(); |
@@ -343,7 +351,6 @@ int main(int narg, const char** args) { | |||
343 | pushYue(L, "pcall"sv); | 351 | pushYue(L, "pcall"sv); |
344 | lua_insert(L, -2); | 352 | lua_insert(L, -2); |
345 | int argCount = 0; | 353 | int argCount = 0; |
346 | i++; | ||
347 | while (i < narg) { | 354 | while (i < narg) { |
348 | argCount++; | 355 | argCount++; |
349 | lua_pushstring(L, args[i]); | 356 | lua_pushstring(L, args[i]); |