添加lua虚拟机状态判断
parent
dd6df86cea
commit
4a3ed972c7
36
README.en.md
36
README.en.md
|
@ -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/)
|
|
@ -19,4 +19,4 @@
|
|||
![image.png](https://www.testingcloud.club/sapi/api/image_download/2184a3b1-a057-11eb-a166-525400dc6cec.png)
|
||||
|
||||
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)
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
}
|
||||
pushstack(para...);
|
||||
}
|
||||
void PrintError(lua_State *L);
|
||||
/* 收到数据发送给lua层进行处理*/
|
||||
void OnDataRecv(QString);
|
||||
void DumpStack();
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
#include <QThread>
|
||||
|
||||
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,6 +48,7 @@ int ShareData::SetQuickView(QQuickView *view)
|
|||
|
||||
int ShareData::OnDataRecv(QByteArray arr)
|
||||
{
|
||||
if(mLuaStatus)
|
||||
mLua.OnDataRecv(QString(arr));
|
||||
}
|
||||
|
||||
|
@ -106,9 +110,11 @@ int ShareData::UpdateLuaScript(QString str)
|
|||
qDebug()<<str;
|
||||
int ret = mLua.DoString(mLuaScript);
|
||||
if(ret < 0){
|
||||
qDebug()<<"保存qml失败";
|
||||
qDebug()<<"更新lua脚本失败";
|
||||
mLuaStatus = false;
|
||||
return -1;
|
||||
}
|
||||
mLuaStatus = true;
|
||||
}
|
||||
|
||||
int ShareData::SaveLuaScript(QString s)
|
||||
|
@ -116,18 +122,21 @@ int ShareData::SaveLuaScript(QString s)
|
|||
QFile file("Test.lua"); //---打开文件
|
||||
if (file.open(QIODevice::WriteOnly) )
|
||||
{
|
||||
//---待存入文本文件的字符串。
|
||||
//-----将数据写入文件
|
||||
qint64 LineLen = file.write(s.toStdString().c_str(), s.size());
|
||||
//----同上,写入文件失败,将返回 -1
|
||||
if (-1 != LineLen)
|
||||
if (LineLen > 0)
|
||||
{
|
||||
//---输出写入文件的内容
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
//----关闭文件
|
||||
file.close();
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
bool ShareData::LuaStatus()
|
||||
{
|
||||
return mLuaStatus;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue