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
| 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 | * |
nothing calls this directly
no test coverage detected