lua 命令行参数

--test.lua

if arg[1] == '1' then
    print("Hello World!")
elseif arg[1] == '2' then
    print("Hi, Captain!")
else
  print("Hi, Tom")
end

 

root@test# lua test.lua 1
Hello World!
root@test# lua test.lua 2
Hi, Captain!

遍历参数:

--test.lua
for i, v in pairs(arg) do
    print(i, v)
end

 

Lua教程:https://www.runoob.com/lua/lua-tutorial.html

posted @ 2021-12-24 10:18  船长博客  阅读(370)  评论(0编辑  收藏  举报
永远相信美好的事情即将发生!