From 797ee134fa8d244f1836eba4fe39b1321c510553 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Thu, 15 Apr 2021 00:52:05 +0800 Subject: [PATCH] no message --- protoDebuger/lua_wraper.cpp | 11 ++++++++++- protoDebuger/lua_wraper.h | 4 ++-- protoDebuger/main.cpp | 1 - protoDebuger/main.qml | 2 ++ protoDebuger/sharedata.cpp | 6 ++++++ protoDebuger/sharedata.h | 5 ++++- 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/protoDebuger/lua_wraper.cpp b/protoDebuger/lua_wraper.cpp index 17cbd85..2db20f0 100644 --- a/protoDebuger/lua_wraper.cpp +++ b/protoDebuger/lua_wraper.cpp @@ -17,6 +17,15 @@ int LuaDelegate::DoString(QString scr) return 0; } +void LuaDelegate::OnDataRecv(){ + int i = lua_getglobal(mVM,"add"); + lua_pushstring(mVM,"test"); + lua_pushnumber(mVM,1); + lua_call(mVM,2,0); + + +} + LuaDelegate::~LuaDelegate() { if(nullptr != mVM){ @@ -37,7 +46,7 @@ int LuaDelegate::DoFile(QString path) { if(mVM != nullptr){ luaL_openlibs(mVM); //打开标准库 - int ret = luaL_loadfile(mVM, path.toStdString().c_str()); + int ret = luaL_dofile(mVM, path.toStdString().c_str()); if (ret > 0){ printf("lua error"); return -1; diff --git a/protoDebuger/lua_wraper.h b/protoDebuger/lua_wraper.h index db7d41f..5953bea 100644 --- a/protoDebuger/lua_wraper.h +++ b/protoDebuger/lua_wraper.h @@ -43,9 +43,9 @@ public: } pushstack(para...); } - void OnDataRecv(){ + /* 收到数据发送给lua层进行处理*/ + void OnDataRecv(); - } ~LuaDelegate(); private: diff --git a/protoDebuger/main.cpp b/protoDebuger/main.cpp index 7f7aead..c035628 100644 --- a/protoDebuger/main.cpp +++ b/protoDebuger/main.cpp @@ -39,7 +39,6 @@ int main(int argc, char *argv[]) view.setTitle ("多用途通信协议调试器,基于lua"); view.rootContext()->setContextProperty("DataWrap",&gGlobal); - TestLua(); view.show(); QObject *qmlObject = view.findChild("SerialSelect",Qt::FindChildOption::FindChildrenRecursively); diff --git a/protoDebuger/main.qml b/protoDebuger/main.qml index 68d151b..b7b8f85 100644 --- a/protoDebuger/main.qml +++ b/protoDebuger/main.qml @@ -82,6 +82,8 @@ Rectangle { console.log(DataWrap) console.log(DataWrap._txt) DataWrap.getValFromQml(1) + + DataWrap.TestLua(); } background: Image { anchors.fill: parent diff --git a/protoDebuger/sharedata.cpp b/protoDebuger/sharedata.cpp index 6a3b6fd..db35fbe 100644 --- a/protoDebuger/sharedata.cpp +++ b/protoDebuger/sharedata.cpp @@ -3,6 +3,7 @@ ShareData::ShareData(QObject *parent) : QObject(parent) { mSerialController = new SerialController(nullptr); + mLua.DoFile("Test.lua"); } int ShareData::OpenUart(QString port, QString baudRate, QString dataBits, QString stopBits, QString flow) @@ -26,3 +27,8 @@ int ShareData::CloseSerial() qDebug()<<"cloase serial failed"; return -1; } + +int ShareData::TestLua() +{ + mLua.OnDataRecv(); +} diff --git a/protoDebuger/sharedata.h b/protoDebuger/sharedata.h index 041d87c..9e749e2 100644 --- a/protoDebuger/sharedata.h +++ b/protoDebuger/sharedata.h @@ -4,6 +4,7 @@ #include "serialcontroller.h" #include #include +#include "lua_wraper.h" class ShareData : public QObject { @@ -31,6 +32,8 @@ public: QString flow); Q_INVOKABLE int CloseSerial(); + Q_INVOKABLE int TestLua(); + QString _txt = "hello world\r\n"; signals: @@ -39,7 +42,7 @@ signals: private: SerialController *mSerialController; - + LuaDelegate mLua; }; #endif // SHAREDATA_H