交互式 lua:命令行参数 [英] interactive lua: command line arguments

查看:28
本文介绍了交互式 lua:命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做

 lua prog.lua arg1 arg2

从命令行

在prog.lua里面,我想说,比如

Inside prog.lua, I want to say, for instance

print (arg1, arg2, '
')

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

Lua doesn't seem to have argv[1] etc and the methods I've seen for dealing with command line arguments seem to be immature and / or cumbersome. Am I missing something?

推荐答案

你缺少了 arg 向量,它在 arg[1] 中有你想要的元素、arg[2] 等:

You're missing the arg vector, which has the elements you want in arg[1], arg[2], and so on:

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

关于 Lua 独立版的 Lua 手册部分中的更多信息(感谢英里!).

More info in the Lua manual section on Lua standalone (thanks Miles!).

这篇关于交互式 lua:命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆