loads a buffer from a resource or disk path * The sys.load_buffer function will first try to load the resource * from any of the mounted resource locations and return the data if * any matching entries found. If not, the path will be tried * as is from the primary disk on the device. * * In order for the engine to include custom resources in the build process, you nee
| 237 | * ``` |
| 238 | */ |
| 239 | static int Sys_LoadBuffer(lua_State* L) |
| 240 | { |
| 241 | int top = lua_gettop(L); |
| 242 | const char* filename = luaL_checkstring(L, 1); |
| 243 | |
| 244 | LuaRequest request; |
| 245 | dmResource::LoadBufferType load_buffer_data; |
| 246 | dmResource::Result res = HandleRequestLoading(g_SysModule.m_Factory, filename, filename, &load_buffer_data, &request); |
| 247 | |
| 248 | if (res != dmResource::RESULT_OK) |
| 249 | { |
| 250 | return luaL_error(L, "sys.load_buffer failed to load the resource (code=%d)", (int) res); |
| 251 | } |
| 252 | |
| 253 | dmBuffer::StreamDeclaration streams_decl[] = {{ dmHashString64("data"), dmBuffer::VALUE_TYPE_UINT8, 1 }}; |
| 254 | |
| 255 | dmBuffer::HBuffer buffer = 0; |
| 256 | dmBuffer::Create(load_buffer_data.Size(), streams_decl, 1, &buffer); |
| 257 | |
| 258 | uint8_t* buffer_data = 0; |
| 259 | uint32_t buffer_datasize = 0; |
| 260 | dmBuffer::GetBytes(buffer, (void**) &buffer_data, &buffer_datasize); |
| 261 | memcpy(buffer_data, load_buffer_data.Begin(), load_buffer_data.Size()); |
| 262 | |
| 263 | dmScript::LuaHBuffer luabuf(buffer, dmScript::OWNER_LUA); |
| 264 | dmScript::PushBuffer(L, luabuf); |
| 265 | |
| 266 | assert(top + 1 == lua_gettop(L)); |
| 267 | return 1; |
| 268 | } |
| 269 | |
| 270 | /*# loads a buffer from a resource or disk path asynchronously |
| 271 | * The sys.load_buffer function will first try to load the resource |
nothing calls this directly
no test coverage detected