添加保存lua脚本功能
This commit is contained in:
parent
6c8dc03e1d
commit
2e8a7cbc8a
@ -1,15 +1 @@
|
|||||||
require("string")
|
require("string")
function OnNewClient(ip,port)
showdata("on new client from lua " .. ip..port.."32232323\r\n")
end
function OnClientRecvData(data)
showdata("client recieve data from lua "..data.."\r\n")
end
function OnClientDisconnect(ip,port)
showdata("client leave from lua " .. ip..port)
end
|
||||||
|
|
||||||
function OnNewClient(ip,port)
|
|
||||||
showdata("on new client from lua " .. ip..port)
|
|
||||||
end
|
|
||||||
|
|
||||||
function OnClientRecvData(data)
|
|
||||||
showdata("client recieve data from lua "..data)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function OnClientDisconnect(ip,port)
|
|
||||||
showdata("client leave from lua " .. ip..port)
|
|
||||||
end
|
|
||||||
|
|
@ -2,6 +2,12 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "lua_bind.h"
|
#include "lua_bind.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define TCP_CLIENT_SCRIPT "tcp_client.lua"
|
||||||
|
TcpClientForm::~TcpClientForm() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
TcpClientForm::TcpClientForm(ui::Window* hwnd,std::string url, uint32_t port, TcpClientLibevent* p):
|
TcpClientForm::TcpClientForm(ui::Window* hwnd,std::string url, uint32_t port, TcpClientLibevent* p):
|
||||||
m_connected(false),
|
m_connected(false),
|
||||||
mLua(nullptr)
|
mLua(nullptr)
|
||||||
@ -13,14 +19,14 @@ TcpClientForm::TcpClientForm(ui::Window* hwnd,std::string url, uint32_t port, Tc
|
|||||||
}
|
}
|
||||||
|
|
||||||
mLua = new LuaDelegate;
|
mLua = new LuaDelegate;
|
||||||
mLuaFile.open("tcp_client.lua");
|
mLuaFileRead.open(TCP_CLIENT_SCRIPT);
|
||||||
std::string lua_script;
|
std::string lua_script;
|
||||||
if (mLuaFile.is_open()) {
|
if (mLuaFileRead.is_open()) {
|
||||||
std::string s;
|
std::string s;
|
||||||
while (getline(mLuaFile, s)) {
|
while (getline(mLuaFileRead, s)) {
|
||||||
lua_script += s + "\r\n";
|
lua_script += s + "\r\n";
|
||||||
}
|
}
|
||||||
mLuaFile.close();
|
mLuaFileRead.close();
|
||||||
}
|
}
|
||||||
mLuaScript = lua_script;
|
mLuaScript = lua_script;
|
||||||
mLua->DoString(lua_script);
|
mLua->DoString(lua_script);
|
||||||
@ -28,7 +34,6 @@ TcpClientForm::TcpClientForm(ui::Window* hwnd,std::string url, uint32_t port, Tc
|
|||||||
std::cout << "lua script is " << lua_script << std::endl;
|
std::cout << "lua script is " << lua_script << std::endl;
|
||||||
m_url = url;
|
m_url = url;
|
||||||
m_port = port;
|
m_port = port;
|
||||||
mLua = new LuaDelegate();
|
|
||||||
this->mLua->BindFunction("showdata", LuaShowData);
|
this->mLua->BindFunction("showdata", LuaShowData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +86,10 @@ void TcpClientForm::Init()
|
|||||||
std::string lua = wstring2string(m_rich_edit_2->GetText());
|
std::string lua = wstring2string(m_rich_edit_2->GetText());
|
||||||
if (0 == this->mLua->UpdateScript(lua)) {
|
if (0 == this->mLua->UpdateScript(lua)) {
|
||||||
this->mLuaScript = lua;
|
this->mLuaScript = lua;
|
||||||
|
mLuaFileEdit = std::ofstream(TCP_CLIENT_SCRIPT, std::ios::out | std::ios::trunc);
|
||||||
|
mLuaFileEdit.write(lua.c_str(), lua.size());
|
||||||
|
mLuaFileEdit.flush();
|
||||||
|
mLuaFileEdit.close();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MessageBox(0, L"lua½Å±¾´íÎó", L"", 0);
|
MessageBox(0, L"lua½Å±¾´íÎó", L"", 0);
|
||||||
|
@ -29,6 +29,7 @@ class TcpClientForm :
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
TcpClientForm(ui::Window* hwnd,string url, uint32_t port, TcpClientLibevent* p);
|
TcpClientForm(ui::Window* hwnd,string url, uint32_t port, TcpClientLibevent* p);
|
||||||
|
~TcpClientForm();
|
||||||
virtual void Init() override;
|
virtual void Init() override;
|
||||||
TcpClientLibevent* ClientEvent();
|
TcpClientLibevent* ClientEvent();
|
||||||
LuaDelegate* LuaVM();
|
LuaDelegate* LuaVM();
|
||||||
@ -52,7 +53,9 @@ private:
|
|||||||
ui::CheckBox* m_check_box_3;
|
ui::CheckBox* m_check_box_3;
|
||||||
ui::CheckBox* m_check_box_4;
|
ui::CheckBox* m_check_box_4;
|
||||||
TcpClientLibevent* mClient;
|
TcpClientLibevent* mClient;
|
||||||
std::ifstream mLuaFile;
|
std::fstream mLuaFileRead;
|
||||||
|
std::ofstream mLuaFileEdit;
|
||||||
|
|
||||||
virtual void HandleMessage(ui::EventArgs& msg);
|
virtual void HandleMessage(ui::EventArgs& msg);
|
||||||
std::string mLuaScript;
|
std::string mLuaScript;
|
||||||
std::string m_url;
|
std::string m_url;
|
||||||
|
@ -1,16 +1 @@
|
|||||||
require("string")
|
require("string")
local file = io.open("writetest.txt", "w+")
function OnNewClient(ip,port)
showdata("on new client from lua " .. ip..port)
end
function OnClientRecvData(data,ip,port)
showdata("client recieve data from lua "..data.. ip..port)
end
function OnClientDisconnect(ip,port)
showdata("client leave from lua " .. ip..port)
end
|
||||||
local file = io.open("writetest.txt", "w+")
|
|
||||||
|
|
||||||
function OnNewClient(ip,port)
|
|
||||||
showdata("on new client from lua " .. ip..port)
|
|
||||||
end
|
|
||||||
|
|
||||||
function OnClientRecvData(data,ip,port)
|
|
||||||
showdata("client recieve data from lua "..data.. ip..port)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function OnClientDisconnect(ip,port)
|
|
||||||
showdata("client leave from lua " .. ip..port)
|
|
||||||
end
|
|
||||||
|
|
@ -12,6 +12,13 @@ extern "C" {
|
|||||||
#include "event2/thread.h"
|
#include "event2/thread.h"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define TCP_SERVER_SCRIPT "tcp_server.lua"
|
||||||
|
TcpServerFrom::~TcpServerFrom() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TcpServerFrom::TcpServerFrom(ui::Window* hwnd, string url,
|
TcpServerFrom::TcpServerFrom(ui::Window* hwnd, string url,
|
||||||
uint32_t port, TcpServerLibevent* p):
|
uint32_t port, TcpServerLibevent* p):
|
||||||
mLua(nullptr)
|
mLua(nullptr)
|
||||||
@ -22,14 +29,14 @@ TcpServerFrom::TcpServerFrom(ui::Window* hwnd, string url,
|
|||||||
mFlagSelectClient = true;
|
mFlagSelectClient = true;
|
||||||
|
|
||||||
mLua = new LuaDelegate;
|
mLua = new LuaDelegate;
|
||||||
mLuaFile.open("tcp_server.lua");
|
mLuaFileRead.open(TCP_SERVER_SCRIPT);
|
||||||
std::string lua_script;
|
std::string lua_script;
|
||||||
if (mLuaFile.is_open()) {
|
if (mLuaFileRead.is_open()) {
|
||||||
std::string s;
|
std::string s;
|
||||||
while (getline(mLuaFile, s)) {
|
while (getline(mLuaFileRead, s)) {
|
||||||
lua_script += s + "\r\n";
|
lua_script += s + "\r\n";
|
||||||
}
|
}
|
||||||
mLuaFile.close();
|
mLuaFileRead.close();
|
||||||
}
|
}
|
||||||
mLuaScript = lua_script;
|
mLuaScript = lua_script;
|
||||||
mLua->DoString(lua_script);
|
mLua->DoString(lua_script);
|
||||||
@ -102,6 +109,10 @@ void TcpServerFrom::Init()
|
|||||||
std::string lua = wstring2string(mEditLua->GetText());
|
std::string lua = wstring2string(mEditLua->GetText());
|
||||||
if (0 == this->mLua->UpdateScript(lua)) {
|
if (0 == this->mLua->UpdateScript(lua)) {
|
||||||
this->mLuaScript = lua;
|
this->mLuaScript = lua;
|
||||||
|
mLuaFileEdit = std::ofstream(TCP_SERVER_SCRIPT, std::ios::out | std::ios::trunc);
|
||||||
|
mLuaFileEdit.write(lua.c_str(), lua.size());
|
||||||
|
mLuaFileEdit.flush();
|
||||||
|
mLuaFileEdit.close();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MessageBox(0, L"lua½Å±¾´íÎó", L"", 0);
|
MessageBox(0, L"lua½Å±¾´íÎó", L"", 0);
|
||||||
|
@ -17,6 +17,7 @@ class TcpServerFrom :
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TcpServerFrom(ui::Window* hwnd, string url, uint32_t port, TcpServerLibevent* p);
|
TcpServerFrom(ui::Window* hwnd, string url, uint32_t port, TcpServerLibevent* p);
|
||||||
|
~TcpServerFrom();
|
||||||
TcpServerLibevent* ServerP();
|
TcpServerLibevent* ServerP();
|
||||||
virtual void Init() override;
|
virtual void Init() override;
|
||||||
void OnNewConnAccept(ConnectionLibevent*);
|
void OnNewConnAccept(ConnectionLibevent*);
|
||||||
@ -47,7 +48,8 @@ private:
|
|||||||
ui::Label* m_label_2;
|
ui::Label* m_label_2;
|
||||||
ui::Combo* m_combo_1;
|
ui::Combo* m_combo_1;
|
||||||
ui::Button* m_button_3;
|
ui::Button* m_button_3;
|
||||||
std::ifstream mLuaFile;
|
std::ifstream mLuaFileRead;
|
||||||
|
std::ofstream mLuaFileEdit;
|
||||||
bool mFlagSelectClient;
|
bool mFlagSelectClient;
|
||||||
LuaDelegate *mLua;
|
LuaDelegate *mLua;
|
||||||
std::string mLuaScript;
|
std::string mLuaScript;
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "lua_bind.h"
|
#include "lua_bind.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define UART_LUA_SCRIPT "uart_script.lua"
|
||||||
UartForm::UartForm(ui::Window* hwnd,std::wstring name,
|
UartForm::UartForm(ui::Window* hwnd,std::wstring name,
|
||||||
uint32_t baurate,UINT portnum,
|
uint32_t baurate,UINT portnum,
|
||||||
uint8_t data_bits, uint8_t stop_bits,
|
uint8_t data_bits, uint8_t stop_bits,
|
||||||
@ -24,7 +26,7 @@ UartForm::UartForm(ui::Window* hwnd,std::wstring name,
|
|||||||
m_runing = true;
|
m_runing = true;
|
||||||
mLua = new LuaDelegate;
|
mLua = new LuaDelegate;
|
||||||
|
|
||||||
mLuaFile.open("script.lua");
|
mLuaFile.open(UART_LUA_SCRIPT);
|
||||||
std::string lua_script;
|
std::string lua_script;
|
||||||
if (mLuaFile.is_open()) {
|
if (mLuaFile.is_open()) {
|
||||||
std::string s;
|
std::string s;
|
||||||
@ -69,6 +71,8 @@ UartForm::UartForm(ui::Window* hwnd,std::wstring name,
|
|||||||
UartForm::~UartForm()
|
UartForm::~UartForm()
|
||||||
{
|
{
|
||||||
SerialPort::ClosePort(m_portnum);
|
SerialPort::ClosePort(m_portnum);
|
||||||
|
mLuaFile.clear();
|
||||||
|
mLuaFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UartForm::ShowDataInEdit(const char*p) {
|
void UartForm::ShowDataInEdit(const char*p) {
|
||||||
|
@ -29,7 +29,7 @@ public:
|
|||||||
uint8_t verify,
|
uint8_t verify,
|
||||||
uint8_t flow_control);
|
uint8_t flow_control);
|
||||||
~UartForm();
|
~UartForm();
|
||||||
|
|
||||||
void ShowDataInEdit(const char*) override;
|
void ShowDataInEdit(const char*) override;
|
||||||
void OnUpdateUart();
|
void OnUpdateUart();
|
||||||
LuaDelegate* LuaVM();
|
LuaDelegate* LuaVM();
|
||||||
@ -55,6 +55,7 @@ public:
|
|||||||
LuaDelegate* mLua;
|
LuaDelegate* mLua;
|
||||||
std::string mLuaScript;
|
std::string mLuaScript;
|
||||||
std::ifstream mLuaFile;
|
std::ifstream mLuaFile;
|
||||||
|
std::ofstream mLuaFileEdit;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void HandleMessage(ui::EventArgs& msg);
|
virtual void HandleMessage(ui::EventArgs& msg);
|
||||||
|
Loading…
Reference in New Issue
Block a user