Wireshark-dev: [Wireshark-dev] Lua embedded into C++

Date Prev · Date Next · Thread Prev · Thread Next
From: Kunal Thakrar <kunalthakrar@xxxxxxxxxxxxx>
Date: Wed, 1 Feb 2017 00:06:07 +0000

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.


TCPAnalyser_dialog.cpp

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();
luaL_openlibs(state);
    
   //this function below is giving errors
       wslua_register_classes(state);

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
msgBox.setText(f);
msgBox.exec();
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
msgBox.setText(f);
msgBox.exec();



}


>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


make-reg.pl

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:


register_wslua.h


#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);
#endif


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)" (?Analyse@TCPAnalyserTreeWidget@@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.

Any help would be most appreciated!

Thanks in advance,

Kind Regards,
Kunal Thakrar