MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / switchname

Function switchname

modules/engine/lua/src/build.skr_lua.cpp:380–444  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

378 (void)resource;
379 const char* key = luaL_checkstring(L, 2);
380 switchname(key)
381 {
382 casestr("resolve")
383 {
384 lua_pushcfunction(
385 L, +[](lua_State* L) -> int {
386 auto resource = (skr_resource_handle_t*)luaL_checkudata(L, 1, "skr_resource_handle_t");
387 bool requireInstall = lua_toboolean(L, 2);
388 if (!resource->is_resolved())
389 resource->resolve(requireInstall, (uint64_t)L, SKR_REQUESTER_SCRIPT);
390 return 0;
391 }, "resolve");
392 return 1;
393 }
394 casestr("is_resolved")
395 {
396 lua_pushcfunction(
397 L, +[](lua_State* L) -> int {
398 auto resource = (skr_resource_handle_t*)luaL_checkudata(L, 1, "skr_resource_handle_t");
399 lua_pushboolean(L, resource->is_resolved());
400 return 1;
401 }, "is_resolved");
402 return 1;
403 }
404 casestr("get_resolved")
405 {
406 lua_pushcfunction(
407 L, +[](lua_State* L) -> int {
408 auto resource = (skr_resource_handle_t*)luaL_checkudata(L, 1, "skr_resource_handle_t");
409 if (!resource->is_resolved())
410 {
411 return 0;
412 }
413 auto ptr = resource->get_resolved();
414 if (!ptr)
415 {
416 return 0;
417 }
418 auto tid = resource->get_type();
419 auto type = skr::rttr::get_type_from_guid(tid);
420 lua_pushlightuserdata(L, ptr);
421 luaL_getmetatable(L, (const char*)type->name().c_str());
422 lua_setmetatable(L, -2);
423 return 1;
424 }, "get_resolved");
425 return 1;
426 }
427 casestr("unload")
428 {
429 lua_pushcfunction(
430 L, +[](lua_State* L) -> int {
431 auto resource = (skr_resource_handle_t*)luaL_checkudata(L, 1, "skr_resource_handle_t");
432 if (resource->is_resolved())
433 resource->unload();
434 else
435 SKR_LOG_DEBUG(u8"skr_resource_handle_t::unload called on unresolved resource.");
436 return 0;
437 }, "unload");

Callers

nothing calls this directly

Calls 14

get_type_from_guidFunction · 0.85
lua_pushlightuserdataFunction · 0.85
luaL_errorFunction · 0.85
is_resolvedMethod · 0.80
luaL_checkudataFunction · 0.50
lua_tobooleanFunction · 0.50
lua_pushbooleanFunction · 0.50
lua_setmetatableFunction · 0.50
resolveMethod · 0.45
get_resolvedMethod · 0.45
get_typeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected