From da3b7c0fc5b3907d513992500781d4a74ef88748 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Fri, 11 Feb 2022 11:31:24 +0800 Subject: [PATCH] no message --- examples/proto_debuger/base_form.cpp | 5 + examples/proto_debuger/proto_debuger.vcxproj | 3 +- examples/proto_debuger/udp_form.cpp | 115 +++++++++++++++++-- examples/proto_debuger/udp_form.h | 2 + 4 files changed, 115 insertions(+), 10 deletions(-) diff --git a/examples/proto_debuger/base_form.cpp b/examples/proto_debuger/base_form.cpp index 789f13c7..f5fc4edf 100644 --- a/examples/proto_debuger/base_form.cpp +++ b/examples/proto_debuger/base_form.cpp @@ -371,6 +371,11 @@ LuaBindInterface* BasicForm::FindCurrentFormByLuaPointer(lua_State* pointer) return (LuaBindInterface*)itr->second; } } + for (auto itr = mUdpForm.begin(); itr != mUdpForm.end(); itr++) { + if (itr->second->LuaVM()->VM() == pointer) { + return (LuaBindInterface*)itr->second; + } + } return nullptr; } diff --git a/examples/proto_debuger/proto_debuger.vcxproj b/examples/proto_debuger/proto_debuger.vcxproj index 8bb7ee8f..401125c1 100644 --- a/examples/proto_debuger/proto_debuger.vcxproj +++ b/examples/proto_debuger/proto_debuger.vcxproj @@ -193,8 +193,6 @@ - - @@ -204,6 +202,7 @@ + diff --git a/examples/proto_debuger/udp_form.cpp b/examples/proto_debuger/udp_form.cpp index 47c2df3f..7f145bc4 100644 --- a/examples/proto_debuger/udp_form.cpp +++ b/examples/proto_debuger/udp_form.cpp @@ -1,29 +1,126 @@ #include "udp_form.h" +#include +#include "utils.h" +#include "lua_bind.h" + + +#define UDP_LUA_SCRIPT "udp_script.lua" UdpForm::UdpForm(ui::Window* hwnd, string url, uint32_t port, UdpDataGramLibevent* p) { this->mUdpPeer = p; this->m_url = url; this->m_port = port; + mLua = new LuaDelegate; + + mLuaFile.open(UDP_LUA_SCRIPT); + std::string lua_script; + if (mLuaFile.is_open()) { + std::string s; + while (getline(mLuaFile, s)) { + lua_script += s + "\r\n"; + } + mLuaFile.close(); + } + mLuaScript = lua_script; + mLua->DoString(lua_script); + + UdpDataGramLibevent::OnReadDataHandle onRecvCallBack([this](const char* dat, int len, struct sockaddr_in sendarr){ + //this->LuaVM()->CallFuntion(); + this->mLua->CallFuntion("OnUdpData", std::string(dat), + inet_ntoa(sendarr.sin_addr),sendarr.sin_port); + }); + if (mUdpPeer != nullptr) { + mUdpPeer->SetOnReadHandle(&onRecvCallBack); + } + this->mLua->BindFunction("showdata", LuaShowData); + + std::cout << "lua script is " << lua_script << std::endl; } UdpForm::~UdpForm() { + } void UdpForm::Init() { ui::ChildBox::Init(); + m_label_1 = dynamic_cast(FindSubControl(L"uart_info_label")); + m_rich_edit_1 = dynamic_cast(FindSubControl(L"uart_recv_eidt")); + if (nullptr != m_rich_edit_1) { + m_rich_edit_1->SetReadOnly(true); + m_rich_edit_1->SetRich(false); + m_rich_edit_1->SetAttribute(L"autovscroll", L"true"); + m_rich_edit_1->SetAttribute(L"multiline", L"true"); + m_rich_edit_1->SetReturnMsgWantCtrl(true); + m_rich_edit_1->SetNeedReturnMsg(true); + m_rich_edit_1->SetWordWrap(true); + } - ui::Label* m_label_1 = dynamic_cast(FindSubControl(L"uart_info_label")); - ui::RichEdit* m_rich_edit_1 = dynamic_cast(FindSubControl(L"uart_recv_eidt")); - ui::RichEdit* m_rich_edit_2 = dynamic_cast(FindSubControl(L"lua_script")); - ui::RichEdit* m_rich_edit_3 = dynamic_cast(FindSubControl(L"uart_send_edit")); - ui::Button* m_button_1 = dynamic_cast(FindSubControl(L"btn_send_data")); - ui::Button* m_button_2 = dynamic_cast(FindSubControl(L"btn_close_uart")); - ui::Button* m_button_3 = dynamic_cast(FindSubControl(L"btn_save_lua")); - ui::Button* m_button_4 = dynamic_cast(FindSubControl(L"btn_do_lua")); + m_rich_edit_2 = dynamic_cast(FindSubControl(L"lua_script")); + if (nullptr != m_rich_edit_2) { + m_rich_edit_2->SetRich(true); + m_rich_edit_2->SetReturnMsgWantCtrl(true); + m_rich_edit_2->SetText(string2wstring(mLuaScript)); + } + + m_rich_edit_3 = dynamic_cast(FindSubControl(L"uart_send_edit")); + m_button_1 = dynamic_cast(FindSubControl(L"btn_send_data")); + m_button_2 = dynamic_cast(FindSubControl(L"btn_close_uart")); + m_button_3 = dynamic_cast(FindSubControl(L"btn_save_lua")); + m_button_4 = dynamic_cast(FindSubControl(L"btn_do_lua")); + + if (nullptr != m_label_1) { + m_label_1->SetText(wstring(L"udp:") + string2wstring(m_url) + + L":" + std::to_wstring(m_port)); + } + if (nullptr != m_button_1) { + m_button_1->AttachClick( + [this](ui::EventArgs*) { + + return true; + } + ); + } + if (nullptr != m_button_2) { + m_button_2->AttachClick( + [this](ui::EventArgs*) { + + return true; + } + ); + } + if (nullptr != m_button_3) { + m_button_3->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; + mLuaFileEdit = std::ofstream(UDP_LUA_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); + return true; + } + std::cout << lua.c_str() << "\r\n"; + return true; + } + ); + } + if (nullptr != m_button_4) { + m_button_4->AttachClick( + [this](ui::EventArgs* ev) { + + return true; + } + ); + } } @@ -34,8 +131,10 @@ LuaDelegate* UdpForm::LuaVM() void UdpForm::ShowDataInEdit(const char*) { + } void UdpForm::HandleMessage(ui::EventArgs& msg) { + } diff --git a/examples/proto_debuger/udp_form.h b/examples/proto_debuger/udp_form.h index ce0b3c29..d76ec126 100644 --- a/examples/proto_debuger/udp_form.h +++ b/examples/proto_debuger/udp_form.h @@ -45,6 +45,8 @@ private: ui::Button* m_button_3; ui::Button* m_button_4; + std::ifstream mLuaFile; + std::ofstream mLuaFileEdit; virtual void HandleMessage(ui::EventArgs& msg); std::string mLuaScript;