get resource buffer * gets the buffer from a resource * * @name resource.get_buffer * * @param path [type:hash|string] The path to the resource * @return buffer [type:buffer] The resource buffer * * @examples * How to get the data from a buffer * * ```lua * function init(self) * * local res_path = go.get("#mesh", "vertices") * local buf = resource.get_buffer(res_path) *
| 3285 | * ``` |
| 3286 | */ |
| 3287 | static int GetBuffer(lua_State* L) |
| 3288 | { |
| 3289 | int top = lua_gettop(L); |
| 3290 | dmhash_t path_hash = dmScript::CheckHashOrString(L, 1); |
| 3291 | |
| 3292 | void* resource = CheckResource(L, g_ResourceModule.m_Factory, path_hash, "bufferc"); |
| 3293 | |
| 3294 | dmGameSystem::BufferResource* buffer_resource = (dmGameSystem::BufferResource*)resource; |
| 3295 | |
| 3296 | if (!dmBuffer::IsBufferValid(buffer_resource->m_Buffer)) |
| 3297 | { |
| 3298 | return luaL_error(L, "The buffer handle is invalid"); |
| 3299 | } |
| 3300 | |
| 3301 | dmResource::IncRef(g_ResourceModule.m_Factory, buffer_resource); |
| 3302 | dmScript::LuaHBuffer luabuf(g_ResourceModule.m_Factory, (void*)buffer_resource); |
| 3303 | PushBuffer(L, luabuf); |
| 3304 | |
| 3305 | assert(top + 1 == lua_gettop(L)); |
| 3306 | return 1; |
| 3307 | } |
| 3308 | |
| 3309 | /*# set resource buffer |
| 3310 | * Sets the buffer of a resource. By default, setting the resource buffer will either copy the data from the incoming buffer object |
no test coverage detected