Bind net functions

This commit is contained in:
Henrique Santiago 2012-08-07 14:05:55 -03:00
parent 0e67bd97a5
commit 4919bdf1bc
3 changed files with 7 additions and 5 deletions

View File

@ -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");

View File

@ -41,11 +41,12 @@ uint32 string_to_ip(const std::string& string)
return ip;
}
void listSubnetAddresses(std::string subnet, std::vector<uint32>& list)
std::vector<uint32> listSubnetAddresses(const std::string& subnet)
{
std::vector<uint32> list;
std::vector<std::string> 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<uint32>(strVec[1]);
if(mask <= 32) {
@ -57,8 +58,7 @@ void listSubnetAddresses(std::string subnet, std::vector<uint32>& list)
}
}
}
return list;
}
}

View File

@ -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<uint32>& list);
std::vector<uint32> listSubnetAddresses(const std::string& subnet);
}
#endif