Wireshark-dev: Re: [Wireshark-dev] Lua embedded into C++
From: Pascal Quantin <[email protected]>
Date: Wed, 1 Feb 2017 16:45:23 +0100
Hi Kunal,

2017-02-01 1:06 GMT+01:00 Kunal Thakrar <[email protected]>:

Hello all,

I am currently trying to embed Wireshark's Lua into my C++ GUI that I have made in order to customise Wireshark. 

So far I have gone about adding the following to my existing GUI code.


extern "C"
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "epan\wslua\register_wslua.h"
//.... other includes for GUI Code here

//... Other GUI code here

void TCPAnalyserTreeWidget::Analyse(){
//More of my own code

       lua_State *state = luaL_newstate();
   //this function below is giving errors

QMessageBox msgBox;
// run the Lua script
QString f;
int lua1;

const char* filename = "alert.lua";
//load file
lua1 = luaL_loadfile(state, filename);
if (lua1 != LUA_OK){
f = "Loadfilefail";
        //debug code
int lua;
lua = luaL_dofile(state, filename);

if (lua !=LUA_OK){
f = "dofilefailed";
const char* message = lua_tostring(state, -1);
f = message;
lua_pop(state, 1);
       //debug code


>From here I have gone and edited the Perl script which writes the file register_wslua.c (which from what I understand adds Wireshark functions and classes to the Lua state) as this would be rewritten during each build of the wslua project


print C '#include "register_wslua.h"' . "\n\n";

#print C '#include "wslua.h"' . "\n\n";
#print C '#include "lua_bitop.h"' . "\n\n";

other than the two prints being commented out and the addition of my include in place of config.h it is left unchanged

The header File I created is as follows:


#include "config.h"
#include "epan\wslua\wslua.h"
#include "epan\wslua\lua_bitop.h"

#ifndef _register_wslua_h
#define _register_wslua_h
static void wslua_reg_module(lua_State* L, const char *name _U_, lua_CFunction func);
void wslua_register_classes(lua_State* L);
void wslua_register_functions(lua_State* L);

From what I understand this should be working, however, I am getting the following errors:

Error 1 error LNK2019: unresolved external symbol _wslua_register_classes referenced in function "private: void __thiscall TCPAnalyserTreeWidget::Analyse(void)" ([email protected][email protected]@AAEXXZ) C:\Users\Kunal\Work\FinalProject\Development\wsbuild32_1\qtui.lib(TCPAnalyser_dialog.obj) wireshark

Error 2 error LNK1120: 1 unresolved externals C:\Users\Kunal\Work\FinalProject\Development\wsbuild32_1\run\RelWithDebInfo\Wireshark.exe 1 1 wireshark

I can't for the life of me figure out why these errors are occurring and I was wondering if there was something I was missing. I have done a clean and a build again just to make sure it was this which was causing the issue. I am getting the same errors if instead of doing all of this, I just include the epan\wslua\declare_wslua.h instead which points to the same functions.

Because those symbols are part of libwireshark library (not the GUI) and are not exported. So you cannot access them.
Not sure what you are trying to do here, but prsumably they should be declared with the WS_DLL_PUBLIC attribute (you will need to include ws_symbol_export.h file to get its definition).

I personally do not know anything about Lua, so I do not know if you can safely create a new instance like this (some comments in the code suggest that only a single Lua state is supported)  but this sounds hacky and scary.

Any help would be most appreciated!

Thanks in advance,

Kind Regards,
Kunal Thakrar

Sent via:    Wireshark-dev mailing list <[email protected]>
Archives:    https://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://www.wireshark.org/mailman/options/wireshark-dev
             mailto:[email protected]wireshark.org?subject=unsubscribe