添加lua虚拟机状态判断

master
zcy 2021-04-20 23:35:18 +08:00
parent dd6df86cea
commit 4a3ed972c7
7 changed files with 103 additions and 74 deletions

View File

@ -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/)

View File

@ -19,4 +19,4 @@
![image.png](https://www.testingcloud.club/sapi/api/image_download/2184a3b1-a057-11eb-a166-525400dc6cec.png) ![image.png](https://www.testingcloud.club/sapi/api/image_download/2184a3b1-a057-11eb-a166-525400dc6cec.png)
lua脚本调试</br> lua脚本调试</br>
![image.png](https://www.testingcloud.club/sapi/api/image_download/36748542-a057-11eb-a166-525400dc6cec.png) ![image.png](https://www.testingcloud.club/sapi/api/image_download/6ec69d99-a1e3-11eb-a166-525400dc6cec.png)

View File

@ -1,7 +1,8 @@
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Controls 1.4 import QtQuick.Controls 2.4
import QtQuick.Layouts 1.0 import QtQuick.Layouts 1.0
import QtQuick.Controls.Styles 1.4 import QtQuick.Controls.Material 2.12
Item { Item {
objectName: "ProtoDebug" objectName: "ProtoDebug"
@ -52,34 +53,55 @@ Item {
font.pixelSize: 30 font.pixelSize: 30
font.bold: true font.bold: true
} }
TextArea { Flickable {
id: lua_script id: flick
Layout.preferredHeight: parent.height - 100 Layout.preferredHeight: parent.height - 100
text: lua_script_text
font.pixelSize: 15
Layout.columnSpan: 1
Layout.preferredWidth: parent.width/2 - 20 Layout.preferredWidth: parent.width/2 - 20
style: TextAreaStyle { Layout.columnSpan: 1
textColor: "#333"
selectionColor: "steelblue" contentWidth: lua_script.paintedWidth
selectedTextColor: "#eee" contentHeight: lua_script.paintedHeight
backgroundColor: "#eee" clip: true
}
Layout.leftMargin: 10 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 { TextArea {
id: text_output id: text_output
Layout.preferredHeight: parent.height - 100 Layout.preferredHeight: parent.height - 100
text: qsTr("") text: qsTr("")
font.pixelSize: 15 font.pixelSize: 17
Layout.columnSpan: 1 Layout.columnSpan: 1
Layout.preferredWidth: parent.width/2 - 20 Layout.preferredWidth: parent.width/2 - 20
style: TextAreaStyle { background: Rectangle {
textColor: "#333" border.color: text_output.enabled ? "#21be2b" : "transparent"
selectionColor: "steelblue"
selectedTextColor: "#eee"
backgroundColor: "#eee"
} }
Layout.leftMargin: 10 Layout.leftMargin: 10
@ -96,8 +118,15 @@ Item {
onClicked: { onClicked: {
lua_script_text = lua_script.text 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 { Button {
@ -109,17 +138,38 @@ Item {
onClicked: { onClicked: {
lua_script_text = lua_script.text 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){ function addString(str){
showbuf = str showbuf += str;
text_output.text = showbuf; text_output.text = showbuf;
} }
} }

View File

@ -17,11 +17,15 @@ int LuaDelegate::DoString(QString scr)
return 0; return 0;
} }
void LuaDelegate::PrintError(lua_State *L)
{
printf("\nFATAL ERROR:%s\n\n", lua_tostring(L, -1));
}
void LuaDelegate::OnDataRecv(QString data){ void LuaDelegate::OnDataRecv(QString data){
int i = lua_getglobal(mVM,"add"); int i = lua_getglobal(mVM,"OnDataReady");
lua_pushstring(mVM,data.toStdString().data()); lua_pushstring(mVM,data.toStdString().data());
lua_pushnumber(mVM,1); lua_call(mVM,1,0);
lua_call(mVM,2,0);
} }
void LuaDelegate::DumpStack() void LuaDelegate::DumpStack()

View File

@ -42,6 +42,7 @@ public:
} }
pushstack(para...); pushstack(para...);
} }
void PrintError(lua_State *L);
/* 收到数据发送给lua层进行处理*/ /* 收到数据发送给lua层进行处理*/
void OnDataRecv(QString); void OnDataRecv(QString);
void DumpStack(); void DumpStack();

View File

@ -5,7 +5,8 @@
#include <QThread> #include <QThread>
ShareData::ShareData(QObject *parent) : QObject(parent), ShareData::ShareData(QObject *parent) : QObject(parent),
mView(nullptr) mView(nullptr),
mLuaStatus(false)
{ {
mSerialController = new SerialController(nullptr); mSerialController = new SerialController(nullptr);
QFile file("Test.lua"); QFile file("Test.lua");
@ -18,6 +19,8 @@ ShareData::ShareData(QObject *parent) : QObject(parent),
int ret = mLua.DoString(mLuaScript); int ret = mLua.DoString(mLuaScript);
if(ret < 0){ if(ret < 0){
qDebug()<<"默认lua脚本加载错误"; qDebug()<<"默认lua脚本加载错误";
}else{
mLuaStatus = true;
} }
} }
@ -45,7 +48,8 @@ int ShareData::SetQuickView(QQuickView *view)
int ShareData::OnDataRecv(QByteArray arr) int ShareData::OnDataRecv(QByteArray arr)
{ {
mLua.OnDataRecv(QString(arr)); if(mLuaStatus)
mLua.OnDataRecv(QString(arr));
} }
int ShareData::ShowDataInQML(QString x) int ShareData::ShowDataInQML(QString x)
@ -106,9 +110,11 @@ int ShareData::UpdateLuaScript(QString str)
qDebug()<<str; qDebug()<<str;
int ret = mLua.DoString(mLuaScript); int ret = mLua.DoString(mLuaScript);
if(ret < 0){ if(ret < 0){
qDebug()<<"保存qml失败"; qDebug()<<"更新lua脚本失败";
mLuaStatus = false;
return -1; return -1;
} }
mLuaStatus = true;
} }
int ShareData::SaveLuaScript(QString s) int ShareData::SaveLuaScript(QString s)
@ -116,18 +122,21 @@ int ShareData::SaveLuaScript(QString s)
QFile file("Test.lua"); //---打开文件 QFile file("Test.lua"); //---打开文件
if (file.open(QIODevice::WriteOnly) ) if (file.open(QIODevice::WriteOnly) )
{ {
//---待存入文本文件的字符串。
//-----将数据写入文件 //-----将数据写入文件
qint64 LineLen = file.write(s.toStdString().c_str(), s.size()); qint64 LineLen = file.write(s.toStdString().c_str(), s.size());
//----同上,写入文件失败,将返回 -1 if (LineLen > 0)
if (-1 != LineLen)
{ {
//---输出写入文件的内容
return -1; return -1;
} }
} }
//----关闭文件
file.close(); file.close();
return 0;
}
bool ShareData::LuaStatus()
{
return mLuaStatus;
} }

View File

@ -44,6 +44,7 @@ public:
Q_INVOKABLE int TestShowData(); Q_INVOKABLE int TestShowData();
Q_INVOKABLE int UpdateLuaScript(QString); Q_INVOKABLE int UpdateLuaScript(QString);
Q_INVOKABLE int SaveLuaScript(QString); Q_INVOKABLE int SaveLuaScript(QString);
Q_INVOKABLE bool LuaStatus();
QString _txt = "hello world\r\n"; QString _txt = "hello world\r\n";
@ -56,7 +57,7 @@ private:
LuaDelegate mLua; LuaDelegate mLua;
QObject *mProtoDebug; QObject *mProtoDebug;
QObject *mRootObj; QObject *mRootObj;
bool mLuaStatus;
QString mLuaScript; QString mLuaScript;
QQuickView *mView; QQuickView *mView;
}; };