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

Function URL_new

engine/script/src/script_msg.cpp:336–452  ·  view source on GitHub ↗

creates a new URL from separate arguments * * @name msg.url * @param [socket] [type:string|hash] socket of the URL * @param [path] [type:string|hash] path of the URL * @param [fragment] [type:string|hash] fragment of the URL * @return url [type:url] a new URL * @examples * * ```lua * local my_socket = "main" -- specify by valid name * local my

Source from the content-addressed store, hash-verified

334 * ```
335 */
336 int URL_new(lua_State* L)
337 {
338 int top = lua_gettop(L);
339 (void)top;
340 dmMessage::URL url;
341 dmMessage::ResetURL(&url);
342 if (top < 2)
343 {
344 ResolveURL(L, 1, &url, 0x0);
345 }
346 else if (top == 3)
347 {
348 dmMessage::URL source;
349 if (lua_isnil(L, 1))
350 {
351 dmMessage::ResetURL(&source);
352 GetURL(L, &source);
353 }
354 if (!lua_isnil(L, 1))
355 {
356 dmhash_t* phash = dmScript::ToHash(L, 1);
357 if (phash != 0)
358 {
359 url.m_Socket = *phash;
360 }
361 else
362 {
363 const char* s = lua_tostring(L, 1);
364 dmMessage::Result result = dmMessage::GetSocket(s, &url.m_Socket);
365 switch (result)
366 {
367 case dmMessage::RESULT_OK:
368 case dmMessage::RESULT_NAME_OK_SOCKET_NOT_FOUND:
369 break;
370 case dmMessage::RESULT_INVALID_SOCKET_NAME:
371 return luaL_error(L, "The socket '%s' name is invalid.", s);
372 default:
373 return luaL_error(L, "Error when getting socket '%s': %d.", s, result);
374 }
375 }
376 }
377 else
378 {
379 url.m_Socket = source.m_Socket;
380 }
381 if (!lua_isnil(L, 2))
382 {
383 if (lua_isstring(L, 2))
384 {
385 const char* path = lua_tostring(L, 2);
386 if (lua_isnil(L, 1) || (lua_isstring(L, 1) && *lua_tostring(L, 1) == '\0'))
387 {
388 size_t path_size = strlen(path);
389 if (path_size > 0)
390 {
391 ResolvePath(L, path, path_size, url.m_Path);
392 }
393 else

Callers

nothing calls this directly

Calls 12

lua_gettopFunction · 0.85
ResetURLFunction · 0.85
ToHashFunction · 0.85
luaL_errorFunction · 0.85
lua_isstringFunction · 0.85
ResolvePathFunction · 0.85
CheckHashFunction · 0.85
PushURLFunction · 0.85
ResolveURLFunction · 0.70
GetURLFunction · 0.70
GetSocketFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected