From 36edad039ceccfee5b5fc3f0e7b350e26fc1cec9 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 4 Dec 2024 12:05:10 +0300 Subject: [PATCH] add string socket:send overload --- doc/en/scripting/builtins/libnetwork.md | 2 +- doc/ru/scripting/builtins/libnetwork.md | 2 +- src/logic/scripting/lua/libs/libnetwork.cpp | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/en/scripting/builtins/libnetwork.md b/doc/en/scripting/builtins/libnetwork.md index 8f4b01eba..48caefbdc 100644 --- a/doc/en/scripting/builtins/libnetwork.md +++ b/doc/en/scripting/builtins/libnetwork.md @@ -39,7 +39,7 @@ The Socket class has the following methods: ```lua -- Sends a byte array -socket:send(table|ByteArray) +socket:send(table|ByteArray|str) -- Reads the received data socket:recv( diff --git a/doc/ru/scripting/builtins/libnetwork.md b/doc/ru/scripting/builtins/libnetwork.md index a2304ed97..7fedf2bd8 100644 --- a/doc/ru/scripting/builtins/libnetwork.md +++ b/doc/ru/scripting/builtins/libnetwork.md @@ -39,7 +39,7 @@ network.tcp_connect( ```lua -- Отправляет массив байт -socket:send(table|ByteArray) +socket:send(table|ByteArray|str) -- Читает полученные данные socket:recv( diff --git a/src/logic/scripting/lua/libs/libnetwork.cpp b/src/logic/scripting/lua/libs/libnetwork.cpp index cce000670..61d44de78 100644 --- a/src/logic/scripting/lua/libs/libnetwork.cpp +++ b/src/logic/scripting/lua/libs/libnetwork.cpp @@ -87,6 +87,9 @@ static int l_send(lua::State* L) { connection->send( reinterpret_cast(bytes->data().data()), bytes->data().size() ); + } else if (lua::isstring(L, 2)) { + auto string = lua::tolstring(L, 2); + connection->send(string.data(), string.length()); } return 0; }