MCPcopy Create free account
hub / github.com/defold/defold / URL_newindex

Function URL_newindex

engine/script/src/script_msg.cpp:156–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154 }
155
156 static int URL_newindex(lua_State *L)
157 {
158 dmMessage::URL* url = (dmMessage::URL*)lua_touserdata(L, 1);
159
160 const char* key = luaL_checkstring(L, 2);
161 if (strcmp("socket", key) == 0)
162 {
163 dmhash_t* phash = dmScript::ToHash(L, 3);
164 if (phash != 0)
165 {
166 url->m_Socket = *phash;
167 }
168 else if (lua_isstring(L, 3))
169 {
170 const char* socket_name = lua_tostring(L, 3);
171 dmMessage::Result result = dmMessage::GetSocket(socket_name, &url->m_Socket);
172 if (!(result == dmMessage::RESULT_OK || result == dmMessage::RESULT_NAME_OK_SOCKET_NOT_FOUND))
173 {
174 if(result == dmMessage::RESULT_INVALID_SOCKET_NAME)
175 {
176 return luaL_error(L, "The socket '%s' name is invalid.", socket_name);
177 }
178 else
179 {
180 return luaL_error(L, "Error when getting socket '%s': %d.", socket_name, result);
181 }
182 }
183 }
184 else if (lua_isnil(L, 3))
185 {
186 url->m_Socket = 0;
187 }
188 else
189 {
190 return luaL_error(L, "Invalid type for socket, must be number, string or nil.");
191 }
192 }
193 else if (strcmp("path", key) == 0)
194 {
195 if (lua_isstring(L, 3))
196 {
197 url->m_Path = dmHashString64(lua_tostring(L, 3));
198 }
199 else if (lua_isnil(L, 3))
200 {
201 url->m_Path = 0;
202 }
203 else
204 {
205 dmhash_t* phash = dmScript::ToHash(L, 3);
206 if (phash != 0)
207 {
208 url->m_Path = *phash;
209 }
210 else
211 {
212 return luaL_error(L, "Invalid type for path, must be hash, string or nil.");
213 }

Callers

nothing calls this directly

Calls 5

lua_touserdataFunction · 0.85
ToHashFunction · 0.85
lua_isstringFunction · 0.85
luaL_errorFunction · 0.85
GetSocketFunction · 0.70

Tested by

no test coverage detected