| 65 | } |
| 66 | |
| 67 | bool LUASocketAddress::Read(Exception& ex, lua_State *pState, int index, SocketAddress& address,bool withDNS) { |
| 68 | |
| 69 | if (lua_isnumber(pState, index)) { |
| 70 | // just port? |
| 71 | address.set(IPAddress::Wildcard(), (UInt16)lua_tonumber(pState, index)); |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | if (lua_type(pState, index)==LUA_TSTRING) { // lua_type because can be encapsulated in a lua_next |
| 76 | const char* value = lua_tostring(pState,index); |
| 77 | if (lua_type(pState, ++index)==LUA_TSTRING) |
| 78 | return withDNS ? address.setWithDNS(ex, value, lua_tostring(pState,index)) : address.set(ex, value, lua_tostring(pState,index)); |
| 79 | if (lua_isnumber(pState,index)) |
| 80 | return withDNS ? address.setWithDNS(ex, value, (UInt16)lua_tonumber(pState,index)) : address.set(ex, value, (UInt16)lua_tonumber(pState,index)); |
| 81 | return withDNS ? address.setWithDNS(ex, value) : address.set(ex, value); |
| 82 | } |
| 83 | |
| 84 | if(lua_istable(pState,index)) { |
| 85 | bool isConst; |
| 86 | |
| 87 | SocketAddress* pOther = Script::ToObject<SocketAddress>(pState, isConst, index); |
| 88 | if (pOther) { |
| 89 | address.set(*pOther); |
| 90 | return true; |
| 91 | } |
| 92 | |
| 93 | IPAddress* pHost = Script::ToObject<IPAddress>(pState, isConst, index); |
| 94 | if (pHost) { |
| 95 | if (lua_type(pState, ++index)==LUA_TSTRING) |
| 96 | return address.set(ex, *pHost, lua_tostring(pState, index)); |
| 97 | if (lua_isnumber(pState, index)) { |
| 98 | address.set(*pHost, (UInt16)lua_tonumber(pState, index)); |
| 99 | return true; |
| 100 | } |
| 101 | return address.set(ex, *pHost, 0); |
| 102 | } |
| 103 | |
| 104 | ServerConnection* pServer = Script::ToObject<ServerConnection>(pState, isConst, index); |
| 105 | if (pServer) { |
| 106 | address.set(pServer->address); |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | } |
| 111 | |
| 112 | ex.set(Exception::SOFTWARE, "No valid SocketAddress available to read"); |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | int LUASocketAddress::Set(lua_State *pState) { |
| 117 | SCRIPT_CALLBACK(SocketAddress, address) |
nothing calls this directly
no test coverage detected