From 4a3ed972c7b7131638e2c8eccb419a65abf32373 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Tue, 20 Apr 2021 23:35:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0lua=E8=99=9A=E6=8B=9F?= =?UTF-8?q?=E6=9C=BA=E7=8A=B6=E6=80=81=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 36 ------------- README.md | 2 +- protoDebuger/ProtoDebug.qml | 100 +++++++++++++++++++++++++++--------- protoDebuger/lua_wraper.cpp | 10 ++-- protoDebuger/lua_wraper.h | 1 + protoDebuger/sharedata.cpp | 25 ++++++--- protoDebuger/sharedata.h | 3 +- 7 files changed, 103 insertions(+), 74 deletions(-) delete mode 100644 README.en.md diff --git a/README.en.md b/README.en.md deleted file mode 100644 index 1231a91..0000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# protoDebuger - -#### Description -基于lua qml 的协议调试软件 - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md index b05c6fc..84e0ed9 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,4 @@ ![image.png](https://www.testingcloud.club/sapi/api/image_download/2184a3b1-a057-11eb-a166-525400dc6cec.png) lua脚本调试
-![image.png](https://www.testingcloud.club/sapi/api/image_download/36748542-a057-11eb-a166-525400dc6cec.png) \ No newline at end of file +![image.png](https://www.testingcloud.club/sapi/api/image_download/6ec69d99-a1e3-11eb-a166-525400dc6cec.png) \ No newline at end of file diff --git a/protoDebuger/ProtoDebug.qml b/protoDebuger/ProtoDebug.qml index 5bbf40b..14d6170 100644 --- a/protoDebuger/ProtoDebug.qml +++ b/protoDebuger/ProtoDebug.qml @@ -1,7 +1,8 @@ import QtQuick 2.0 -import QtQuick.Controls 1.4 +import QtQuick.Controls 2.4 import QtQuick.Layouts 1.0 -import QtQuick.Controls.Styles 1.4 +import QtQuick.Controls.Material 2.12 + Item { objectName: "ProtoDebug" @@ -52,34 +53,55 @@ Item { font.pixelSize: 30 font.bold: true } - TextArea { - id: lua_script + Flickable { + id: flick Layout.preferredHeight: parent.height - 100 - text: lua_script_text - font.pixelSize: 15 - Layout.columnSpan: 1 Layout.preferredWidth: parent.width/2 - 20 - style: TextAreaStyle { - textColor: "#333" - selectionColor: "steelblue" - selectedTextColor: "#eee" - backgroundColor: "#eee" - } + Layout.columnSpan: 1 + + contentWidth: lua_script.paintedWidth + contentHeight: lua_script.paintedHeight + clip: true Layout.leftMargin: 10 + ColorAnimation { + from: "white" + to: "white" + duration: 200 + } + function ensureVisible(r) + { + if (contentX >= r.x) + contentX = r.x; + else if (contentX+width <= r.x+r.width) + contentX = r.x+r.width-width; + if (contentY >= r.y) + contentY = r.y; + else if (contentY+height <= r.y+r.height) + contentY = r.y+r.height-height; + } + + TextEdit { + id: lua_script + focus: true + text: lua_script_text + font.pixelSize: 15 + color: "red" + selectByMouse : true + wrapMode: TextEdit.Wrap + onCursorRectangleChanged: flick.ensureVisible(cursorRectangle) + } } + TextArea { id: text_output Layout.preferredHeight: parent.height - 100 text: qsTr("") - font.pixelSize: 15 + font.pixelSize: 17 Layout.columnSpan: 1 Layout.preferredWidth: parent.width/2 - 20 - style: TextAreaStyle { - textColor: "#333" - selectionColor: "steelblue" - selectedTextColor: "#eee" - backgroundColor: "#eee" + background: Rectangle { + border.color: text_output.enabled ? "#21be2b" : "transparent" } Layout.leftMargin: 10 @@ -96,8 +118,15 @@ Item { onClicked: { lua_script_text = lua_script.text - DataWrap.SaveLuaScript(lua_script_text) - + let ret = DataWrap.SaveLuaScript(lua_script_text) + console.log(ret) + if(ret != 0){ + tip.text = "保存lua脚本失败" + tip.visible = true + return + } + tip.text = "保存lua脚本成功" + tip.visible = true } } Button { @@ -109,17 +138,38 @@ Item { onClicked: { lua_script_text = lua_script.text - DataWrap.UpdateLuaScript(lua_script_text) + let ret = DataWrap.UpdateLuaScript(lua_script_text) + if(ret != 0){ + tip.text = "更新lua脚本失败" + tip.visible = true + return + } + tip.text = "更新lua脚本成功" + tip.visible = true } + } } - - + } + } + ToolTip { + id: tip + text: qsTr("") + visible: false + contentItem: Text { + text: tip.text + font: tip.font + color: "#21be2b" } + background: Rectangle { + border.color: "#21be2b" + } + delay: 100 + timeout: 1000 } function addString(str){ - showbuf = str + showbuf += str; text_output.text = showbuf; } } diff --git a/protoDebuger/lua_wraper.cpp b/protoDebuger/lua_wraper.cpp index 134388e..19e57cc 100644 --- a/protoDebuger/lua_wraper.cpp +++ b/protoDebuger/lua_wraper.cpp @@ -17,11 +17,15 @@ int LuaDelegate::DoString(QString scr) return 0; } +void LuaDelegate::PrintError(lua_State *L) +{ + printf("\nFATAL ERROR:%s\n\n", lua_tostring(L, -1)); +} + void LuaDelegate::OnDataRecv(QString data){ - int i = lua_getglobal(mVM,"add"); + int i = lua_getglobal(mVM,"OnDataReady"); lua_pushstring(mVM,data.toStdString().data()); - lua_pushnumber(mVM,1); - lua_call(mVM,2,0); + lua_call(mVM,1,0); } void LuaDelegate::DumpStack() diff --git a/protoDebuger/lua_wraper.h b/protoDebuger/lua_wraper.h index a8de13b..9dc5221 100644 --- a/protoDebuger/lua_wraper.h +++ b/protoDebuger/lua_wraper.h @@ -42,6 +42,7 @@ public: } pushstack(para...); } + void PrintError(lua_State *L); /* 收到数据发送给lua层进行处理*/ void OnDataRecv(QString); void DumpStack(); diff --git a/protoDebuger/sharedata.cpp b/protoDebuger/sharedata.cpp index 9a57604..5b3412a 100644 --- a/protoDebuger/sharedata.cpp +++ b/protoDebuger/sharedata.cpp @@ -5,7 +5,8 @@ #include ShareData::ShareData(QObject *parent) : QObject(parent), - mView(nullptr) + mView(nullptr), + mLuaStatus(false) { mSerialController = new SerialController(nullptr); QFile file("Test.lua"); @@ -18,6 +19,8 @@ ShareData::ShareData(QObject *parent) : QObject(parent), int ret = mLua.DoString(mLuaScript); if(ret < 0){ qDebug()<<"默认lua脚本加载错误"; + }else{ + mLuaStatus = true; } } @@ -45,7 +48,8 @@ int ShareData::SetQuickView(QQuickView *view) int ShareData::OnDataRecv(QByteArray arr) { - mLua.OnDataRecv(QString(arr)); + if(mLuaStatus) + mLua.OnDataRecv(QString(arr)); } int ShareData::ShowDataInQML(QString x) @@ -106,9 +110,11 @@ int ShareData::UpdateLuaScript(QString str) qDebug()< 0) { - //---输出写入文件的内容 return -1; } } - //----关闭文件 file.close(); + return 0; + +} + +bool ShareData::LuaStatus() +{ + return mLuaStatus; } diff --git a/protoDebuger/sharedata.h b/protoDebuger/sharedata.h index af7575b..f722e51 100644 --- a/protoDebuger/sharedata.h +++ b/protoDebuger/sharedata.h @@ -44,6 +44,7 @@ public: Q_INVOKABLE int TestShowData(); Q_INVOKABLE int UpdateLuaScript(QString); Q_INVOKABLE int SaveLuaScript(QString); + Q_INVOKABLE bool LuaStatus(); QString _txt = "hello world\r\n"; @@ -56,7 +57,7 @@ private: LuaDelegate mLua; QObject *mProtoDebug; QObject *mRootObj; - + bool mLuaStatus; QString mLuaScript; QQuickView *mView; };