Ejemplo n.º 1
0
bool LUAIPAddress::Read(Exception& ex, lua_State *pState, int index, IPAddress& address,bool withDNS) {

	if (lua_type(pState, index)==LUA_TSTRING) // lua_type because can be encapsulated in a lua_next
		return withDNS ? address.setWithDNS(ex, lua_tostring(pState,index)) : address.set(ex, lua_tostring(pState,index));

	if(lua_istable(pState,index)) {
		bool isConst;

		IPAddress* pOther = Script::ToObject<IPAddress>(pState, isConst, index);
		if (pOther) {
			address.set(*pOther);
			return true;
		}

		SocketAddress* pAddress = Script::ToObject<SocketAddress>(pState, isConst, index);
		if (pAddress) {
			address.set(pAddress->host());
			return true;
		}

		ServerConnection* pServer = Script::ToObject<ServerConnection>(pState, isConst, index);
		if (pServer) {
			address.set(pServer->address.host());
			return true;
		}
	}

	ex.set(Exception::NETADDRESS, "No valid IPAddress available to read");
	return false;
}