no message
This commit is contained in:
parent
2603a06533
commit
6c8dc03e1d
@ -1,12 +1,11 @@
|
||||
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)
|
||||
function OnClientRecvData(data)
|
||||
showdata("client recieve data from lua "..data)
|
||||
end
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "tcp_client_form.h"
|
||||
#include "utils.h"
|
||||
#include "lua_bind.h"
|
||||
|
||||
TcpClientForm::TcpClientForm(ui::Window* hwnd,std::string url, uint32_t port, TcpClientLibevent* p):
|
||||
m_connected(false),
|
||||
@ -12,7 +13,7 @@ TcpClientForm::TcpClientForm(ui::Window* hwnd,std::string url, uint32_t port, Tc
|
||||
}
|
||||
|
||||
mLua = new LuaDelegate;
|
||||
mLuaFile.open("tcp_server.lua");
|
||||
mLuaFile.open("tcp_client.lua");
|
||||
std::string lua_script;
|
||||
if (mLuaFile.is_open()) {
|
||||
std::string s;
|
||||
@ -28,6 +29,7 @@ TcpClientForm::TcpClientForm(ui::Window* hwnd,std::string url, uint32_t port, Tc
|
||||
m_url = url;
|
||||
m_port = port;
|
||||
mLua = new LuaDelegate();
|
||||
this->mLua->BindFunction("showdata", LuaShowData);
|
||||
}
|
||||
|
||||
void TcpClientForm::ShowDataInEdit(const char*p) {
|
||||
@ -50,7 +52,9 @@ void TcpClientForm::Init()
|
||||
m_check_box_2 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_time_send"));
|
||||
m_check_box_3 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_send"));
|
||||
m_check_box_4 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_recv"));
|
||||
m_btn_save_lua = dynamic_cast<ui::Button*>(FindSubControl(L"btn_save_lua"));
|
||||
|
||||
|
||||
m_rich_edit_2->SetRich(true);
|
||||
m_rich_edit_2->SetReturnMsgWantCtrl(true);
|
||||
m_rich_edit_2->SetText(string2wstring(mLuaScript));
|
||||
@ -71,6 +75,21 @@ void TcpClientForm::Init()
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (nullptr != m_btn_save_lua) {
|
||||
m_btn_save_lua->AttachClick([this](ui::EventArgs*) {
|
||||
std::cout << "保存lua脚本\r\n";
|
||||
std::string lua = wstring2string(m_rich_edit_2->GetText());
|
||||
if (0 == this->mLua->UpdateScript(lua)) {
|
||||
this->mLuaScript = lua;
|
||||
}
|
||||
else {
|
||||
MessageBox(0, L"lua脚本错误", L"", 0);
|
||||
return true;
|
||||
}
|
||||
std::cout << lua.c_str() << "\r\n";
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
TcpClientLibevent* TcpClientForm::ClientEvent()
|
||||
@ -103,7 +122,11 @@ void TcpClientForm::OnData(uint8_t* dat, uint64_t len)
|
||||
{
|
||||
//std::cout << (char*)dat << "len is " << len << std::endl;
|
||||
//m_rich_edit_1->AppendText(string2wstring(std::string((char*)dat)), false);
|
||||
|
||||
int ret = this->mLua->CallFuntion <std::string>
|
||||
("OnClientRecvData", std::string((char*)dat));
|
||||
if (ret < 0) {
|
||||
MessageBox(0, L"lua脚本错误 OnClientRecvData", L"", 0);
|
||||
}
|
||||
}
|
||||
|
||||
void TcpClientForm::OnClose()
|
||||
|
@ -46,6 +46,7 @@ private:
|
||||
ui::RichEdit* m_rich_edit_2;
|
||||
ui::RichEdit* m_uart_send_edit;
|
||||
ui::Button* m_btn_send_data;
|
||||
ui::Button* m_btn_save_lua;
|
||||
ui::CheckBox* m_check_box_1;
|
||||
ui::CheckBox* m_check_box_2;
|
||||
ui::CheckBox* m_check_box_3;
|
||||
|
@ -23,10 +23,13 @@
|
||||
<CheckBox class="checkbox_font12" name="check_hex_send" text="hex显示" margin="10,12,0,0" selected="true"/>
|
||||
<CheckBox class="checkbox_font12" name="check_hex_recv" text="hex接受" margin="10,12,0,0" selected="true"/>
|
||||
<Button class="btn_global_blue_80x30" name="btn_close_uart" width="100" text="关闭" bkcolor="lightcolor" margin="25,3,5,3" />
|
||||
<Button class="btn_global_blue_80x30" name="btn_save_lua" width="100" text="保存lua脚本" bkcolor="lightcolor" margin="25,3,5,3" />
|
||||
|
||||
</HBox>
|
||||
<HBox height="40">
|
||||
<Button class="btn_global_blue_80x30" name="btn_do_lua" width="100" text="执行" bkcolor="lightcolor" margin="25,3,5,3" />
|
||||
<RichEdit class="simple input" width="stretch" name="lua_do" height="30" margin="5,5,5,5" multiline="true" vscrollbar="true" hscrollbar="true" autovscroll="true" normaltextcolor="darkcolor" wantreturnmsg="true" rich="true" />
|
||||
|
||||
</HBox>
|
||||
</VBox>
|
||||
</ChildBox>
|
||||
|
Loading…
Reference in New Issue
Block a user