From 61dd06ed9f56a15adaf8b4f141d2f7e47670196b Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Thu, 19 Jul 2018 15:06:07 -0700 Subject: [PATCH] Lua: Switch from disable_lua to enable_lua. Deprecate "disable_lua" in favor of "enable_lua". Configuration options typically use "true" or a similar value to enable features. Using "disable_lua = false" to enable Lua seems odd. Change-Id: I224acad0559d409ea0a28b5555d1eb898564328c Reviewed-on: https://code.wireshark.org/review/28773 Reviewed-by: Gerald Combs Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- docbook/wsluarm.asciidoc | 22 ++++++++++++---------- epan/wslua/init_wslua.c | 16 +++++++++++++--- epan/wslua/template-init.lua | 6 +++--- test/lua/globals_2.2.txt | 2 +- tools/pre-commit-ignore.conf | 1 + 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/docbook/wsluarm.asciidoc b/docbook/wsluarm.asciidoc index ab3c96bf88..7861a7d8c1 100644 --- a/docbook/wsluarm.asciidoc +++ b/docbook/wsluarm.asciidoc @@ -20,21 +20,23 @@ the Department of Computer Science. In Wireshark Lua can be used to write dissectors, taps, and capture file readers and writers. -Wireshark’s Lua interpreter starts by loading `init.lua` that is located in the -global configuration directory of Wireshark. Lua is enabled by default. To -disable Lua the line variable _$$disable_lua$$_ should be set to _true_ in -`init.lua`. +Wireshark’s Lua interpreter starts by loading a file named `init.lua` in +Wireshark's global configuration directory. It is enabled by default. To +disable Lua the line variable _$$enable_lua$$_ should be set to _false_ +in _init.lua_. Wireshark 2.6 and earlier enabled and disabled Lua using +the variable _$$disable_lua$$_. It is still supported, but is deprecated +and support may be removed in a future release. _$$enable_lua$$_ takes +precedence over _$$disable_lua$$_. -After loading _init.lua_ from the data directory if Lua is enabled Wireshark -will try to load a file named `init.lua` in the user’s directory. - -Wireshark will also load all files with `.lua` suffix from both the global and -the personal plugins directory. +If Lua is enabled Wireshark will then try to load a file named _init.lua_ +in the user’s personal configuration directory. Wireshark will also load +all files with a _.lua_ suffix from both the global and the personal +plugins directory. The command line option _$$-X lua_script:$$++file.lua++_ can be used to load Lua scripts as well. -The Lua code will be executed once after all the protocol dissectors have being +The Lua code will be executed once after all the protocol dissectors have been initialized and before reading any file. [[wslua_dissector_example]] diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c index 48a5c5e38e..caf05626cf 100644 --- a/epan/wslua/init_wslua.c +++ b/epan/wslua/init_wslua.c @@ -767,6 +767,7 @@ wslua_allocf(void *ud _U_, void *ptr, size_t osize _U_, size_t nsize) void wslua_init(register_cb cb, gpointer client_data) { gchar* filename; const funnel_ops_t* ops = funnel_get_funnel_ops(); + gboolean enable_lua = TRUE; gboolean run_anyway = FALSE; expert_module_t* expert_lua; int file_count = 1; @@ -923,16 +924,25 @@ void wslua_init(register_cb cb, gpointer client_data) { filename = NULL; /* check if lua is to be disabled */ - lua_getglobal(L,"disable_lua"); + lua_getglobal(L, "disable_lua"); // 2.6 and earlier, deprecated + if (lua_isboolean(L,-1)) { + enable_lua = ! lua_toboolean(L,-1); + } + lua_pop(L,1); /* pop the getglobal result */ - if (lua_isboolean(L,-1) && lua_toboolean(L,-1)) { + lua_getglobal(L, "enable_lua"); // 3.0 and later + if (lua_isboolean(L,-1)) { + enable_lua = lua_toboolean(L,-1); + } + lua_pop(L,1); /* pop the getglobal result */ + + if (!enable_lua) { /* disable lua */ lua_close(L); L = NULL; first_time = FALSE; return; } - lua_pop(L,1); /* pop the getglobal result */ /* load global scripts */ lua_load_global_plugins(cb, client_data, FALSE); diff --git a/epan/wslua/template-init.lua b/epan/wslua/template-init.lua index 96888f83eb..9be7050fed 100644 --- a/epan/wslua/template-init.lua +++ b/epan/wslua/template-init.lua @@ -11,10 +11,10 @@ -- -- SPDX-License-Identifier: GPL-2.0-or-later --- Set disable_lua to true to disable Lua support. -disable_lua = false +-- Set enable_lua to false to disable Lua support. +enable_lua = true -if disable_lua then +if not enable_lua then return end diff --git a/test/lua/globals_2.2.txt b/test/lua/globals_2.2.txt index bde560a316..762e497238 100644 --- a/test/lua/globals_2.2.txt +++ b/test/lua/globals_2.2.txt @@ -720,8 +720,8 @@ ["datafile_path"] = '', ["debug"] = '', ["deregister_filehandler"] = '', - ["disable_lua"] = false, ["dofile"] = '', + ["enable_lua"] = true, ["error"] = '', ["expert"] = { ["group"] = { diff --git a/tools/pre-commit-ignore.conf b/tools/pre-commit-ignore.conf index d3f23ca057..7fd791662b 100644 --- a/tools/pre-commit-ignore.conf +++ b/tools/pre-commit-ignore.conf @@ -15,6 +15,7 @@ epan/dissectors/asn1/*/*asn epan/nghttp2/* epan/wmem/wmem_strbuf.c epan/wmem/wmem_strutil.c +epan/wslua/init_wslua.c extcap/* image/stock_icons/* mmdbresolve.c