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