本文介绍了交互式lua:命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做
lua prog.lua arg1 arg2
在prog.lua里面,我想说,例如
Inside prog.lua, I want to say, for instance
print (arg1, arg2, '\n')
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
>
详情请参阅(感谢Miles!)
More info in the Lua manual section on Lua standalone (thanks Miles!).
这篇关于交互式lua:命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!