Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: "Undefined globals" in plugin environment like Wireshark #545

Closed
roddypratt opened this issue May 21, 2021 · 7 comments
Closed

Comments

@roddypratt
Copy link

I'm using Lua for developing Wireshark plugins. Wireshark defines various global objects/functions that must be used by plugins.

This gives a lot of "Undefined global" errors, which I can fix by adding these in the workspace settings Lua.diagnostics.globals

But, is there a better way of managing this so I can create a file like those in meta/template/*.lua and have that added to the globals?

@sumneko
Copy link
Collaborator

sumneko commented May 21, 2021

This is the recommended approach.
You could put the file in your workspace(but never require it in runtime), or use Lua.workspace.library.
Here is an example: https://github.com/Ketho/vscode-wow-api/blob/master/EmmyLua/API/GlobalAPI/compat.lua

@roddypratt
Copy link
Author

Thanks, that's exactly what I need.

@daldr-ntml
Copy link

daldr-ntml commented May 26, 2021

May I ask for clarification on how to do this please?

My lua script general.lua shows this error:

image

so I added a file called compat.lua to my script folder, containing:

---@param name The name of the protocol
---@param desc A Long Text description of the protocol (usually lowercase)
---[Documentation](https://www.wireshark.org/docs/wsdg_html_chunked/wsluarm_modules.html)
function Proto.new(name, desc) end

but general.lua still has the error and compat.lua also shows an error:

image

What am I doing wrong?

@roddypratt
Copy link
Author

You've defined Proto.new(), but not Proto itself.

Add this to your compat.lua.
Proto = {}

I'm working on a more complete one here. https://github.com/roddypratt/router_dissectors/blob/main/wireshark.lua
Feel free to copy/contribute

@daldr-ntml
Copy link

@roddypratt Thanks very much for your answer and for the file.

@Z-LL
Copy link

Z-LL commented Jun 10, 2021

You've defined Proto.new(), but not Proto itself.

Add this to your compat.lua.
Proto = {}

I'm working on a more complete one here. https://github.com/roddypratt/router_dissectors/blob/main/wireshark.lua
Feel free to copy/contribute

Thanks very much!But there is still a small problem: package.prepend_path() undefined , hope it can be fixed.

@roddypratt
Copy link
Author

package.prepend_path() is not a standard Lua function, and AFACIT it's not mentioned in the Wireshark docs either. But, it does exist in Wireshark , and works as expected :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants