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

Function PreCreateResources

engine/gamesys/src/gamesys/scripts/script_resource.cpp:283–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281}
282
283static void PreCreateResources(lua_State* L, const char* path_str, const char** supported_exts, uint32_t num_supported_exts, dmhash_t* canonical_path_hash_out)
284{
285 const char* path_ext = dmResource::GetExtFromPath(path_str);
286 bool path_ok = false;
287 if (path_ext)
288 {
289 for (uint32_t i = 0; i < num_supported_exts; ++i)
290 {
291 const char* ext = supported_exts[i];
292 if (dmStrCaseCmp(path_ext, ext) == 0)
293 {
294 path_ok = true;
295 break;
296 }
297 }
298 }
299
300 if (!path_ok)
301 {
302 char message[1024];
303 dmSnPrintf(message, sizeof(message), "Unable to create resource, path '%s' must have any of the following extensions: ", path_str);
304 for (uint32_t i = 0; i < num_supported_exts; ++i)
305 {
306 dmStrlCat(message, supported_exts[i], sizeof(message));
307 }
308 luaL_error(L, "%s", message);
309 }
310
311 dmhash_t canonical_path_hash = GetCanonicalPathHash(path_str);
312 if (dmResource::FindByHash(g_ResourceModule.m_Factory, canonical_path_hash))
313 {
314 luaL_error(L, "Unable to create resource, a resource is already registered at path '%s'", path_str);
315 }
316
317 *canonical_path_hash_out = canonical_path_hash;
318}
319
320static void PreCreateResource(lua_State* L, const char* path_str, const char* path_ext_wanted, dmhash_t* canonical_path_hash_out)
321{

Callers 2

PreCreateResourceFunction · 0.85
CreateSoundDataFunction · 0.85

Calls 7

GetExtFromPathFunction · 0.85
dmStrCaseCmpFunction · 0.85
dmSnPrintfFunction · 0.85
dmStrlCatFunction · 0.85
luaL_errorFunction · 0.85
GetCanonicalPathHashFunction · 0.85
FindByHashFunction · 0.85

Tested by

no test coverage detected