diff options
author | Hadriel Kaplan <hadrielk@yahoo.com> | 2014-02-09 14:27:51 -0500 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2014-02-13 22:32:58 +0000 |
commit | 58fe488822ef7e59b1f7e85f04d4a19876c39769 (patch) | |
tree | 7661e201e4d2c9194c16e6cff4b98a798b464cb5 /test/lua | |
parent | 1eeb33a7b069311e62b7300b08eb9de5669e7e3f (diff) | |
download | wireshark-58fe488822ef7e59b1f7e85f04d4a19876c39769.tar.gz |
Lua: add ability for scripts loaded from command-line to be passed arguments
This change adds the ability to pass on to lua scripts loaded from the
command-line (tshark or wireshark) additional arguments supplied by the
command-line. This will help us in our testsuites, but also might be
useful for user-created scripts. The additional arguments are passed in
using the '-X' eXtension switch.
Change-Id: Ib94cdf1ffd194ca84692fee7816665e4ff95efbd
Reviewed-on: https://code.wireshark.org/review/156
Reviewed-by: Evan Huus <eapache@gmail.com>
Tested-by: Evan Huus <eapache@gmail.com>
Diffstat (limited to 'test/lua')
-rwxr-xr-x | test/lua/script_args.lua | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/lua/script_args.lua b/test/lua/script_args.lua new file mode 100755 index 0000000000..2bf9d47025 --- /dev/null +++ b/test/lua/script_args.lua @@ -0,0 +1,36 @@ +---------------------------------------- +-- This just verifies the number of args it got is what it expected. +-- The first arg should be a number, for how many total args to expect, +-- including itself. + +local function testing(...) + print("---- Testing "..tostring(...).." ----") +end + +local function test(name, result) + io.stdout:write("test "..name.."...") + if result == true then + io.stdout:write("passed\n") + else + io.stdout:write("failed!\n") + error(name.." test failed!") + end +end + +----------------------------- + +testing("Command-line args") + +local arg={...} -- get passed-in args + +test("arg1", arg ~= nil and #arg > 0) + +local numargs = tonumber(arg[1]) +test("arg2", numargs ~= nil) + +test("arg3", #arg == numargs) + +print("\n-----------------------------\n") + +print("All tests passed!\n\n") + |