From 4ff6d54b09a216648a00f333042fcf32ca8c4b44 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Sat, 5 Mar 2022 22:49:02 +0800 Subject: add global "arg" for CLI arguments. --- src/yue.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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) { return 1; } std::string evalStr = args[i]; + lua_newtable(L); + i++; + for (int j = i, index = 1; j < narg; j++) { + lua_pushstring(L, args[j]); + lua_rawseti(L, -2, index); + index++; + } + lua_setglobal(L, "arg"); std::ifstream input(evalStr, std::ios::in); if (input) { auto ext = fs::path(evalStr).extension().string(); @@ -343,7 +351,6 @@ int main(int narg, const char** args) { pushYue(L, "pcall"sv); lua_insert(L, -2); int argCount = 0; - i++; while (i < narg) { argCount++; lua_pushstring(L, args[i]); -- cgit v1.2.3-55-g6feb