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 Oliver |
One Answer:
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:
answered 12 Dec '14, 05:42 Hadriel |
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 usesetfenv()
if it's 5.1, anddebug.setupvalue()
if it's 5.2 or greater.