no message
parent
96d7d414e2
commit
797ee134fa
|
@ -17,6 +17,15 @@ int LuaDelegate::DoString(QString scr)
|
||||||
return 0;
|
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()
|
LuaDelegate::~LuaDelegate()
|
||||||
{
|
{
|
||||||
if(nullptr != mVM){
|
if(nullptr != mVM){
|
||||||
|
@ -37,7 +46,7 @@ int LuaDelegate::DoFile(QString path)
|
||||||
{
|
{
|
||||||
if(mVM != nullptr){
|
if(mVM != nullptr){
|
||||||
luaL_openlibs(mVM); //打开标准库
|
luaL_openlibs(mVM); //打开标准库
|
||||||
int ret = luaL_loadfile(mVM, path.toStdString().c_str());
|
int ret = luaL_dofile(mVM, path.toStdString().c_str());
|
||||||
if (ret > 0){
|
if (ret > 0){
|
||||||
printf("lua error");
|
printf("lua error");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -43,9 +43,9 @@ public:
|
||||||
}
|
}
|
||||||
pushstack(para...);
|
pushstack(para...);
|
||||||
}
|
}
|
||||||
void OnDataRecv(){
|
/* 收到数据发送给lua层进行处理*/
|
||||||
|
void OnDataRecv();
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
~LuaDelegate();
|
~LuaDelegate();
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -39,7 +39,6 @@ int main(int argc, char *argv[])
|
||||||
view.setTitle ("多用途通信协议调试器,基于lua");
|
view.setTitle ("多用途通信协议调试器,基于lua");
|
||||||
view.rootContext()->setContextProperty("DataWrap",&gGlobal);
|
view.rootContext()->setContextProperty("DataWrap",&gGlobal);
|
||||||
|
|
||||||
TestLua();
|
|
||||||
|
|
||||||
view.show();
|
view.show();
|
||||||
QObject *qmlObject = view.findChild<QObject*>("SerialSelect",Qt::FindChildOption::FindChildrenRecursively);
|
QObject *qmlObject = view.findChild<QObject*>("SerialSelect",Qt::FindChildOption::FindChildrenRecursively);
|
||||||
|
|
|
@ -82,6 +82,8 @@ Rectangle {
|
||||||
console.log(DataWrap)
|
console.log(DataWrap)
|
||||||
console.log(DataWrap._txt)
|
console.log(DataWrap._txt)
|
||||||
DataWrap.getValFromQml(1)
|
DataWrap.getValFromQml(1)
|
||||||
|
|
||||||
|
DataWrap.TestLua();
|
||||||
}
|
}
|
||||||
background: Image {
|
background: Image {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
ShareData::ShareData(QObject *parent) : QObject(parent)
|
ShareData::ShareData(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
mSerialController = new SerialController(nullptr);
|
mSerialController = new SerialController(nullptr);
|
||||||
|
mLua.DoFile("Test.lua");
|
||||||
}
|
}
|
||||||
|
|
||||||
int ShareData::OpenUart(QString port, QString baudRate, QString dataBits, QString stopBits, QString flow)
|
int ShareData::OpenUart(QString port, QString baudRate, QString dataBits, QString stopBits, QString flow)
|
||||||
|
@ -26,3 +27,8 @@ int ShareData::CloseSerial()
|
||||||
qDebug()<<"cloase serial failed";
|
qDebug()<<"cloase serial failed";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ShareData::TestLua()
|
||||||
|
{
|
||||||
|
mLua.OnDataRecv();
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "serialcontroller.h"
|
#include "serialcontroller.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include "lua_wraper.h"
|
||||||
|
|
||||||
class ShareData : public QObject
|
class ShareData : public QObject
|
||||||
{
|
{
|
||||||
|
@ -31,6 +32,8 @@ public:
|
||||||
QString flow);
|
QString flow);
|
||||||
Q_INVOKABLE int CloseSerial();
|
Q_INVOKABLE int CloseSerial();
|
||||||
|
|
||||||
|
Q_INVOKABLE int TestLua();
|
||||||
|
|
||||||
QString _txt = "hello world\r\n";
|
QString _txt = "hello world\r\n";
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -39,7 +42,7 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SerialController *mSerialController;
|
SerialController *mSerialController;
|
||||||
|
LuaDelegate mLua;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHAREDATA_H
|
#endif // SHAREDATA_H
|
||||||
|
|
Loading…
Reference in New Issue