Ask Your Question
0

What is the correct and current way to structure a lua plugin with multiple modules?

asked 2024-07-25 21:50:28 +0000

SteveD gravatar image

updated 2024-07-25 22:26:09 +0000

I have created a Wireshark dissector in lua and this is working. I now need to extend the functionality and so first I have split the single .lua file into multiple modules.

I saw this question, which helped me get the use of the package path correct, as previously I was following examples using package.prepend_path, which I understand has been removed. This basically breaks every example I can find for anyone getting started with Wireshark and lua!

https://ask.wireshark.org/question/34...

Now the I have my dissector split into multiple modules, I have further problems.

If I go to Help->About->Plugins, I see every module in my code listed as a separate plugin. I am not sure if this is correct or not. However, Ctrl-Shift-L loads every module in alphabetical order. When it reaches my main lua file, my main file then loads all the modules as it should. Is this expected behaviour? Some of my modules depend on others, so the load order is important. Am I meant to be using require in my lua scripts (I am at the moment)? It seems like Wireshark is trying to load all the lua sub-modules for me, in which case I don't need to use require, but will have to hack the load order by alphabetically naming the files so they load in the correct sequence. This can't be right. Perhaps I am meant to keep my sub-modules outside the plugins folder. I have searched pretty hard for answers, but haven't found anything that has helped, except the link above that got things going.

At the moment, my main lua module is at C:\Program Files\Wireshark\plugins\mypluginname\init.lua. My sub-modules are in a 'files' folder beneath this.

Can anyone point me to the correct way to structure the files in a Wireshark lua dissector? - What to name the main module. Does it matter? - Where to place the sub-modules. Within the plugins folder structure or elsewhere? - Whether to use require within the main lua file or whether to let Wireshark load them from its recursive search of the folders.

Perhaps there are docs that explain this. If so, a link would be great and apologies that I failed to find it.

edit retag flag offensive close merge delete

Comments

18589: Lua Personal vs Global Plugin Failure

17212: Lua plugin loading order undefined

It seems like Wireshark is trying to load all the lua sub-modules for me

10.1. Introduction

Then all files ending with .lua in the personal Lua plugin’s directory.

I think it's documented somewhere or in an issue that .lua files in sub directories are loaded.
It does load because I've tested it but don't remember if/where it's documented.

Chuckc gravatar imageChuckc ( 2024-07-25 22:49:25 +0000 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2024-07-26 03:23:40 +0000

johnthacker gravatar image

I added a comment to 18589 demonstrating an approach that works. I am not sure it's clearly documented anywhere.

edit flag offensive delete link more

Comments

Here's the link to '18589' for anyone else reading this... https://gitlab.com/wireshark/wireshar...

SteveD gravatar imageSteveD ( 2024-07-26 19:06:26 +0000 )edit

Thanks for the fast replies to my question. The suggested solution under 18589 worked for me.

My main lua module is now under:

C:\Program Files\Wireshark\plugins\mypluginname\mypluginname.lua

I then created a folder...

C:\Program Files\Wireshark\mypluginname

...with all the sub-modules in it.

Within my main lua module, I simply have the line:

package.path = "mypluginname/?.lua;" .. package.path

...so the sub-modules can be found when require is called.

This is a real gem of information - much appreciated!

SteveD gravatar imageSteveD ( 2024-07-26 19:12:58 +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

Stats

Asked: 2024-07-25 21:50:28 +0000

Seen: 123 times

Last updated: Jul 25