Bind net functions
This commit is contained in:
parent
0e67bd97a5
commit
4919bdf1bc
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue