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

Function Set

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

Set a resource * Sets the resource data for a specific resource * * @name resource.set * * @param path [type:string|hash] The path to the resource * @param buffer [type:buffer] The buffer of precreated data, suitable for the intended resource type * * @examples * * Assuming the folder "/res" is added to the project custom resources: * * ```lua * -- load a texture resource and set it o

Source from the content-addressed store, hash-verified

341 * ```
342 */
343static int Set(lua_State* L)
344{
345 int top = lua_gettop(L);
346
347 dmhash_t path_hash = dmScript::CheckHashOrString(L, 1);
348 dmScript::LuaHBuffer* buffer = dmScript::CheckBuffer(L, 2);
349
350 uint32_t datasize = 0;
351 void* data = 0;
352 dmBuffer::GetBytes(buffer->m_Buffer, &data, &datasize);
353
354 dmResource::Result r = dmResource::SetResource(g_ResourceModule.m_Factory, path_hash, data, datasize);
355 if( r != dmResource::RESULT_OK )
356 {
357 assert(top == lua_gettop(L));
358 return ReportPathError(L, r, path_hash);
359 }
360 assert(top == lua_gettop(L));
361 return 0;
362}
363
364/*# load a resource
365 * Loads the resource data for a specific resource.

Callers 4

dmArrayMethod · 0.85
LiveUpdateResourceMethod · 0.85
Box.hFile · 0.85
BoxMethod · 0.85

Calls 7

lua_gettopFunction · 0.85
CheckHashOrStringFunction · 0.85
CheckBufferFunction · 0.85
ReportPathErrorFunction · 0.85
GetBytesFunction · 0.70
SetResourceFunction · 0.50
assertFunction · 0.50

Tested by

no test coverage detected