add socket:get_address, serversocket:get_port

This commit is contained in:
MihailRis
2024-11-30 22:32:14 +03:00
parent 3e949bd499
commit 21c76c1b0d
6 changed files with 66 additions and 12 deletions
@@ -151,6 +151,16 @@ static int l_is_connected(lua::State* L) {
return lua::pushboolean(L, false);
}
static int l_get_address(lua::State* L) {
u64id_t id = lua::tointeger(L, 1);
if (auto connection = engine->getNetwork().getConnection(id)) {
lua::pushstring(L, connection->getAddress());
lua::pushinteger(L, connection->getPort());
return 2;
}
return 0;
}
static int l_is_serveropen(lua::State* L) {
u64id_t id = lua::tointeger(L, 1);
if (auto server = engine->getNetwork().getServer(id)) {
@@ -159,6 +169,14 @@ static int l_is_serveropen(lua::State* L) {
return lua::pushboolean(L, false);
}
static int l_get_serverport(lua::State* L) {
u64id_t id = lua::tointeger(L, 1);
if (auto server = engine->getNetwork().getServer(id)) {
return lua::pushinteger(L, server->getPort());
}
return 0;
}
static int l_get_total_upload(lua::State* L) {
return lua::pushinteger(L, engine->getNetwork().getTotalUpload());
}
@@ -180,6 +198,8 @@ const luaL_Reg networklib[] = {
{"__recv", lua::wrap<l_recv>},
{"__is_alive", lua::wrap<l_is_alive>},
{"__is_connected", lua::wrap<l_is_connected>},
{"__get_address", lua::wrap<l_get_address>},
{"__is_serveropen", lua::wrap<l_is_serveropen>},
{"__get_serverport", lua::wrap<l_get_serverport>},
{NULL, NULL}
};