Ask Your Question

print scope

asked 2019-06-19 14:19:14 +0000

Harvey gravatar image

Hello, I'm a newbie for lua, even though lua is very powerful, fortunately there is the forum to find some answers to some strange behavior for me.

I'm doing some test on my dissector, and I'm using the print function.

I can print until I reach the line 2 :

  1. print("AA") ====> *print correctly
  2. gip_protocol = Proto("TGIP", "TGIP Protocol")
  3. print("AB") ====> never *print

Is there some sort of scope for the print fucntion ?

edit retag flag offensive close merge delete


I created a very basic lua script:

gip_protocol = Proto("TGIP", "TGIP Protocol")

... and then ran tshark -v; both statements printed, e.g.:

tshark -v
TShark (Wireshark) 3.1.0 (v3.1.0rc0-1082-gaf4b67d19a5e)
cmaynard gravatar imagecmaynard ( 2019-06-19 16:17:14 +0000 )edit

sorry I posted too fast. By doing the same test as cmaynard, I got the same problem; In fact I was running the following command line

tshark -r test_210.pcapng -X lua_script:Test.lua -Q  -X lua_script1:arg1 -X lua_script2:arg2 > Test.txt

And looking into the file Test.txt I saw :

argument #1 is:arg1
Bad Data :401//400

... The problem is that I did not saw the error stream on this file, but on the command window there was :

Test.lua:42: bad argument #2 to 'Proto' (Proto_new: there cannot be two protocols with the same description)

Refering to the line

gip_protocol = Proto("TGIP", "TGIP Protocol")

What I don't understand is that even with this error the script continue, and some print contained in functions are still working: but no more the ones in ...(more)

Harvey gravatar imageHarvey ( 2019-06-20 05:59:46 +0000 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-06-20 09:25:13 +0000

grahamb gravatar image

The reason for the error was explained in my answer to your other question about lua arguments; to supply 2 arguments to the same script the "num" element of -X lua_scriptnum:arg1 must refer to the same script. Your 2nd argument of -X lua_script2:arg2 refers to a non-existent 2nd lua script.

I agree the error message is less than helpful in indicating your error.

edit flag offensive delete link more


Hello grahamb, I read your comment and took it into account, but my problem here is to understand why the printing is not done in all the code of the script

Harvey gravatar imageHarvey ( 2019-06-21 07:00:57 +0000 )edit

Please post your full script, or if it's too big, post it on a public share and post a link to it back here. All my tests show there is no issue either with providing multiple arguments or printing at any point in the script.

grahamb gravatar imagegrahamb ( 2019-06-22 10:45:44 +0000 )edit

Here it is GIP.lua And some data in case : data_gip then running tshark -r test_210.pcapng -X lua_script:gip.lua -Q > Test.txt.

Harvey gravatar imageHarvey ( 2019-06-25 07:09:04 +0000 )edit

A quick run of your script and test data works for me. I do get an error about line 341:

tshark: Lua: Error during loading:
gip.lua:341: attempt to index global 'tap' (a nil value)
stack traceback:
        gip.lua:341: in main chunk

You also have print("222") at two different places in the script, but they do both print out.

Note that a print() outside a function will be called once at script load, hence they are all shown at the start of the output. Using print() inside a function will occur when the function is called.

If you still think there are issues you'll have to be more explicit about them.

grahamb gravatar imagegrahamb ( 2019-07-03 12:13:53 +0000 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-06-19 14:19:14 +0000

Seen: 703 times

Last updated: Jun 20 '19