command-line - 交互式 lua : command line arguments

标签 command-line lua interactive

我想做

 lua prog.lua arg1 arg2

从命令行

在prog.lua里面,我想说,比如
print (arg1, arg2, '\n')

Lua 似乎没有 argv[1] 等,我见过的处理命令行参数的方法似乎不成熟和/或繁琐。我错过了什么吗?

最佳答案

您错过了 arg向量,其中包含您想要的元素 arg[1] , arg[2] , 等等:

% lua -i -- /dev/null one two three
Lua 5.1.3  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print(arg[2])
two
> 

更多信息在 Lua manual section on Lua standalone (感谢迈尔斯!)。

关于command-line - 交互式 lua : command line arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2945819/

相关文章:

java - 将字符串从 java 传递到命令行程序

io - 在lua中实时读取控制台输出

python - 如何使用菜单中的键盘箭头导航制作交互式 Python 脚本

command-line - 命令提示符/Bat 文件 - 创建以今天的日期命名的新文件夹

Java Processbuilder 返回 255

macos - 在终端中设置颜色会导致奇怪的字符行限制

lua - Intellij IDEA 自定义自动完成

Lua 脚本 - 在字符串中查找数字

ios - "Control Center"像滑动 View Controller

javascript - 如何使用 SVG map 形状创建可点击链接