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

Function Sys_LoadResource

engine/script/src/script_sys.cpp:717–737  ·  view source on GitHub ↗

loads resource from game data * * Loads a custom resource. Specify the full filename of the resource that you want * to load. When loaded, the file data is returned as a string. * If loading fails, the function returns `nil` plus the error message. * * In order for the engine to include custom resources in the build process, you need * to specify them in the "cus

Source from the content-addressed store, hash-verified

715 * ```
716 */
717 static int Sys_LoadResource(lua_State* L)
718 {
719 int top = lua_gettop(L);
720 const char* filename = luaL_checkstring(L, 1);
721
722 HContext context = dmScript::GetScriptContext(L);
723
724 void* resource;
725 uint32_t resource_size;
726 dmResource::Result r = dmResource::GetRaw(context->m_ResourceFactory, filename, &resource, &resource_size);
727 if (r != dmResource::RESULT_OK) {
728 lua_pushnil(L);
729 lua_pushfstring(L, "Failed to load resource: %s (%d)", filename, r);
730 assert(top + 2 == lua_gettop(L));
731 return 2;
732 }
733 lua_pushlstring(L, (const char*) resource, resource_size);
734 free(resource);
735 assert(top + 1 == lua_gettop(L));
736 return 1;
737 }
738
739 /*# get system information
740 *

Callers

nothing calls this directly

Calls 8

lua_gettopFunction · 0.85
GetRawFunction · 0.85
lua_pushnilFunction · 0.85
lua_pushfstringFunction · 0.85
lua_pushlstringFunction · 0.85
freeFunction · 0.85
GetScriptContextFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected