From 4919bdf1bcc1d4b1bc87f3e9493d926542ca2f2a Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Tue, 7 Aug 2012 14:05:55 -0300 Subject: [PATCH] Bind net functions --- src/framework/luafunctions.cpp | 2 ++ src/framework/stdext/net.cpp | 8 ++++---- src/framework/stdext/net.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 9c6acc04..01f6f622 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -62,6 +62,8 @@ void Application::registerLuaFunctions() g_lua.bindGlobalFunction("colortostring", [](const Color& v) { return stdext::to_string(v); }); g_lua.bindGlobalFunction("sizetostring", [](const Size& v) { return stdext::to_string(v); }); g_lua.bindGlobalFunction("iptostring", [](int v) { return stdext::ip_to_string(v); }); + g_lua.bindGlobalFunction("stringtoip", [](const std::string& v) { return stdext::string_to_ip(v); }); + g_lua.bindGlobalFunction("listSubnetAddresses", [](const std::string& v) { return stdext::listSubnetAddresses(v); }); // Application g_lua.registerSingletonClass("g_app"); diff --git a/src/framework/stdext/net.cpp b/src/framework/stdext/net.cpp index ed8f0cb8..8827c24a 100644 --- a/src/framework/stdext/net.cpp +++ b/src/framework/stdext/net.cpp @@ -41,11 +41,12 @@ uint32 string_to_ip(const std::string& string) return ip; } -void listSubnetAddresses(std::string subnet, std::vector& list) +std::vector listSubnetAddresses(const std::string& subnet) { + std::vector list; std::vector strVec; boost::split(strVec, subnet, boost::is_any_of("/")); - uint32 address = inet_addr(strVec[0].c_str()); + uint32 address = string_to_ip(strVec[0]); if(address != INADDR_NONE && strVec.size() == 2) { uint32 mask = boost::lexical_cast(strVec[1]); if(mask <= 32) { @@ -57,8 +58,7 @@ void listSubnetAddresses(std::string subnet, std::vector& list) } } } + return list; } - - } diff --git a/src/framework/stdext/net.h b/src/framework/stdext/net.h index 7abc299f..4cfedc13 100644 --- a/src/framework/stdext/net.h +++ b/src/framework/stdext/net.h @@ -30,7 +30,7 @@ namespace stdext { std::string ip_to_string(uint32 ip); uint32 string_to_ip(const std::string& string); - void listSubnetAddresses(std::string subnet, std::vector& list); + std::vector listSubnetAddresses(const std::string& subnet); } #endif