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

Function SetSound

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

Update internal sound resource * Update internal sound resource (wavc/oggc/opusc) with new data * * @name resource.set_sound * * @param path [type:hash|string] The path to the resource * @param buffer [type:string] A lua string containing the binary sound data */

Source from the content-addressed store, hash-verified

2914 * @param buffer [type:string] A lua string containing the binary sound data
2915 */
2916static int SetSound(lua_State* L) {
2917 DM_LUA_STACK_CHECK(L, 0);
2918
2919 // get resource path as hash
2920 const dmhash_t path_hash = dmScript::CheckHashOrString(L, 1);
2921 // get the sound buffer
2922 luaL_checktype(L, 2, LUA_TSTRING);
2923 size_t buffer_size;
2924 const char* buffer = lua_tolstring(L, 2, &buffer_size);
2925
2926 dmResource::Result r = dmResource::SetResource(g_ResourceModule.m_Factory, path_hash, (void*) buffer, buffer_size);
2927
2928 if( r != dmResource::RESULT_OK ) {
2929 return ReportPathError(L, r, path_hash);
2930 }
2931
2932 return 0;
2933}
2934
2935static uint8_t* CheckBufferOrString(lua_State* L, int index, uint32_t* data_size)
2936{

Callers

nothing calls this directly

Calls 5

CheckHashOrStringFunction · 0.85
luaL_checktypeFunction · 0.85
lua_tolstringFunction · 0.85
ReportPathErrorFunction · 0.85
SetResourceFunction · 0.50

Tested by

no test coverage detected