diff --git a/doc/release-notes.adoc b/doc/release-notes.adoc index 6c80190e212..f0a5d1d7369 100644 --- a/doc/release-notes.adoc +++ b/doc/release-notes.adoc @@ -87,6 +87,11 @@ The following features are either new or have been significantly updated since v * DNP 3 (Distributed Network Protocol 3) is now supported in the Conversations and Endpoints table dialogs. +* The Lua supplied preloaded libraries `bit` and `rex_pcre2` are loaded in + a way that adds them to the `package.loaded` table, as though through + `require`, so that `require("bit")` and `require("rex_pcre2")` statements + in Lua dissectors, while usually superfluous, behave as expected. wsbuglink:20213[] + * The Windows installers now ship with Npcap 1.80. They previously shipped with Npcap 1.79. diff --git a/doc/wsdg_src/wsdg_lua_support.adoc b/doc/wsdg_src/wsdg_lua_support.adoc index cc0abc0f7f1..1a38f93b444 100644 --- a/doc/wsdg_src/wsdg_lua_support.adoc +++ b/doc/wsdg_src/wsdg_lua_support.adoc @@ -448,7 +448,9 @@ in replacement for code written to use that library by simply replacing a `bit32 = require("bit32")` statement with `bit32 = bit`. [NOTE] -The library is already loaded in the global environment as the `bit` table; -Lua dissectors should not contain a `require("bit")` statement, which will give an -error (unless another copy of the BitOp library is also accessible to the system Lua -outside the Wireshark distributed code.) +The library is already loaded in the global environment as the `bit` table; a +statement like `local bit = require("bit")` is not necessary in Lua dissectors. +On Wireshark versions prior to 4.6 this will give an error (unless another copy +of the BitOp library is also accessible to the system Lua outside the Wireshark +distributed code.) On Wireshark version 4.6 and later such statements behave as +expected but are largely superfluous. diff --git a/epan/wslua/lua_bitop.c b/epan/wslua/lua_bitop.c index 10bfb9bf570..7ade45cd343 100644 --- a/epan/wslua/lua_bitop.c +++ b/epan/wslua/lua_bitop.c @@ -161,7 +161,6 @@ DIAG_ON(unreachable-code) } luaL_newlib(L, bit_funcs); - lua_setglobal(L, "bit"); /* added for wireshark */ - return 0; /* changed from 1 to 0 for wireshark, since lua_setglobal now pops the table */ + return 1; } diff --git a/epan/wslua/make-reg.py b/epan/wslua/make-reg.py index b8ae77b3b58..a3e98b8e9d5 100755 --- a/epan/wslua/make-reg.py +++ b/epan/wslua/make-reg.py @@ -61,14 +61,15 @@ def generate_register_wslua_c(classes, functions, internal_functions): output_lines += ["\tlua_pushcfunction(L, func);"] output_lines += ["\tlua_call(L, 0, 0);"] output_lines += ["}\n"] + output_lines += ["static void wslua_reg_library(lua_State* L, const char *name, lua_CFunction func) {"] + output_lines += ['\tluaL_requiref(L, name, func, 1);'] + output_lines += ['\tlua_pop(L, 1); /* remove lib */'] + output_lines += ["}\n"] output_lines += ["void wslua_register_classes(lua_State* L) {"] for lua_class in classes: output_lines += ["\twslua_reg_module(L, \"{lua_class}\", {lua_class}_register);".format(lua_class=lua_class)] - - output_lines += ["\twslua_reg_module(L, \"bit\", luaopen_bit);"] - output_lines += ["\tlua_pushcfunction(L, luaopen_rex_pcre2);"] - output_lines += ["\tlua_call(L, 0, 1);"] - output_lines += ["\tlua_setglobal(L, \"rex_pcre2\");"] + output_lines += ['\twslua_reg_library(L, "bit", luaopen_bit);'] + output_lines += ['\twslua_reg_library(L, "rex_pcre2", luaopen_rex_pcre2);'] output_lines += ["}\n"] output_lines += ["void wslua_register_functions(lua_State* L) {"]