diff --git a/protoDebuger/CMakeLists.txt b/protoDebuger/CMakeLists.txt index 95bfce8..34fdcb0 100644 --- a/protoDebuger/CMakeLists.txt +++ b/protoDebuger/CMakeLists.txt @@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 3.5) include_directories(third/lua/include) link_directories(third/lua/lib) link_libraries(lua) +set(CMAKE_CXX_STANDARD 17) + project(protoDebuger LANGUAGES CXX) @@ -29,6 +31,7 @@ set(SOURCES # 待预编译的cpp代码 qserialproto.cpp globalvar.cpp sharedata.cpp + lua_wraper.cpp ) set(RESOURCES diff --git a/protoDebuger/lua_wraper.cpp b/protoDebuger/lua_wraper.cpp new file mode 100644 index 0000000..17cbd85 --- /dev/null +++ b/protoDebuger/lua_wraper.cpp @@ -0,0 +1,58 @@ +#include "lua_wraper.h" + +void LuaDelegate::Stop() +{ + +} + +int LuaDelegate::DoString(QString scr) +{ + if (mVM != nullptr){ + int ret = luaL_dostring(mVM,scr.toStdString().c_str()); + if (ret > 0){ + printf("lua error"); + return -1; + } + } + return 0; +} + +LuaDelegate::~LuaDelegate() +{ + if(nullptr != mVM){ + lua_close(mVM); + } +} + +LuaDelegate::LuaDelegate(): + mVM(nullptr) +{ + mVM = luaL_newstate(); //打开lua + if(nullptr != mVM){ + printf("shit is nullptr"); + } +} + +int LuaDelegate::DoFile(QString path) +{ + if(mVM != nullptr){ + luaL_openlibs(mVM); //打开标准库 + int ret = luaL_loadfile(mVM, path.toStdString().c_str()); + if (ret > 0){ + printf("lua error"); + return -1; + } + } + return 0; +} + + + + +void TestLua() +{ + LuaDelegate v; + qDebug()<("test",13,(void *)"sds",false); +} diff --git a/protoDebuger/lua_wraper.h b/protoDebuger/lua_wraper.h index 55a8c50..db7d41f 100644 --- a/protoDebuger/lua_wraper.h +++ b/protoDebuger/lua_wraper.h @@ -3,35 +3,58 @@ #include +#include +#include +#include +#include + + extern "C" { #include "lua.h" #include "lauxlib.h" #include "lualib.h" } -void TestLua(){ - char buff[256]; - int error; - lua_State *L = luaL_newstate(); //打开lua - if(nullptr != L){ - printf("shit is nullptr"); - } - luaL_openlibs(L); //打开标准库 - int ret = luaL_dofile(L, "Test.lua"); - if (ret > 0){ - printf("lua error"); - } - int sum; - //code5 - lua_getglobal(L, "add"); - //code6 - char * data = "hell"; - lua_pushstring(L, data); - //code7 - lua_pushnumber(L, 4); - //code8 - lua_call(L, 2, 1); - lua_close(L); -} + +class LuaDelegate{ +public: + LuaDelegate(); + int DoFile(QString); + void Stop(); + int DoString(QString); + + void pushstack() { +// const std::type_info &t1 = std::bad_typeid(arg1); +// std::cout << t1.name() << std::endl; + } + //单参数模板 + template + void pushstack(T arg1,Types... rest) { + const std::type_info &t1 = typeid(arg1); + qDebug() <//类的成员函数是模板 + void CallFuntion(QString name,T... para){ + int i = lua_getglobal(mVM,name.toStdString().c_str()); + if(i < 0){ + return ; + } + pushstack(para...); + } + void OnDataRecv(){ + + } + + ~LuaDelegate(); +private: + lua_State *mVM; + QString mFile; +}; + +void TestLua(); + + #endif // LUA_WRAPER_H + diff --git a/protoDebuger/main.cpp b/protoDebuger/main.cpp index 3def8d3..7f7aead 100644 --- a/protoDebuger/main.cpp +++ b/protoDebuger/main.cpp @@ -39,8 +39,9 @@ int main(int argc, char *argv[]) view.setTitle ("多用途通信协议调试器,基于lua"); view.rootContext()->setContextProperty("DataWrap",&gGlobal); - view.show(); TestLua(); + + view.show(); QObject *qmlObject = view.findChild("SerialSelect",Qt::FindChildOption::FindChildrenRecursively); qmlObject->setProperty("comlist",comList);