This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Lua behaviour has changed sometime since Wireshark 1.8.7

0

I just upgraded Wireshark from 1.8.7 to the latest stable version (1.12.2) on my Windows machine.

The Lua engine now behaves differently, rendering my plugin dissectors inoperative. I have three dissectors, each in a separate .lua source file, that make use of some common, global, variables that are declared in a fourth .lua source file. All of these sources are placed in my %APPDATA%\Roaming\Wireshark\plugins directory.

After the Lua engine reads all these sources in, all non-local entities declared in any file USED TO BE ACCESSIBLE from any function subsequently run (even if that function were defined in a different source file to the entity's declaration).

Are individual .lua source files now treated as separate namespaces (effectively making all declarations local to their containing file)?

Is there some way to restore the ability to declare entities that can be visible from functions in other sources?

Thanks.

asked 09 Dec '14, 09:05

Tony%20Oliver's gravatar image

Tony Oliver
11112
accept rate: 0%


One Answer:

1

Yes, a long time ago the loading of plugins was changed to be scoped to a separate environment for each plugin file, to prevent clobbering of variables if people forgot to make their variables local.

To handle your use-case, I think you have two options:

  1. In the file that declares your global variables, declare them explicitly as global variables by putting them in the global table. For example, like this:

     _G["myVariable1"] = true
     _G["myVariable2"] = 42
     -- or this syntax
     _G.myVariable3 = false
     _G.myVariable4 = "foobar"
  2. Or, have Wireshark only load the one plugin that declares the common global variables, and in that plugin use dofile() or load file() to load all the other plugins. That way they're all loaded into the same environment.

answered 12 Dec '14, 05:42

Hadriel's gravatar image

Hadriel
2.7k2939
accept rate: 18%

Oh, and I suppose a third option is to have the Lua plugin that declares the global variables change its environment to be the global one. Unfortunately the way this is done is different for Lua 5.1 vs. 5.2, and Wireshark supports both... so if you wanted to support both for your plugin you'd have to check the Lua version first and then do it the appropriate way - this can be done, since there is a global variable for the Lua version (_VERSION if I recall right); so you'd use setfenv() if it's 5.1, and debug.setupvalue() if it's 5.2 or greater.

(12 Dec '14, 05:51) Hadriel