| 200 | } |
| 201 | |
| 202 | static int PushStream(lua_State* L, int bufferindex, dmBuffer::HBuffer buffer, dmhash_t stream_name) |
| 203 | { |
| 204 | DM_LUA_STACK_CHECK(L, 1); |
| 205 | dmBuffer::ValueType type; |
| 206 | uint32_t components; |
| 207 | dmBuffer::Result r = dmBuffer::GetStreamType(buffer, stream_name, &type, &components); |
| 208 | if( r != dmBuffer::RESULT_OK ) |
| 209 | { |
| 210 | return DM_LUA_ERROR("Failed to get stream type: %s", dmBuffer::GetResultString(r)); |
| 211 | } |
| 212 | |
| 213 | void** data; |
| 214 | uint32_t count = 0; |
| 215 | uint32_t stride = 0; |
| 216 | r = dmBuffer::GetStream(buffer, stream_name, (void**)&data, &count, &components, &stride); |
| 217 | if( r != dmBuffer::RESULT_OK ) |
| 218 | { |
| 219 | return DM_LUA_ERROR("Failed to get stream bytes: %s", dmBuffer::GetResultString(r)); |
| 220 | } |
| 221 | |
| 222 | FStreamGetter getter = GetGetter(type); |
| 223 | FStreamSetter setter = GetSetter(type); |
| 224 | if (getter == 0 || setter == 0) |
| 225 | { |
| 226 | return DM_LUA_ERROR("Failed to get stream getter and setter!"); |
| 227 | } |
| 228 | |
| 229 | BufferStream* p = (BufferStream*)lua_newuserdata(L, sizeof(BufferStream)); |
| 230 | p->m_Buffer = buffer; |
| 231 | p->m_Name = stream_name; |
| 232 | p->m_Data = data; |
| 233 | p->m_Count = count; |
| 234 | p->m_Stride = stride; |
| 235 | p->m_Type = type; |
| 236 | p->m_TypeCount = components; |
| 237 | p->m_Set = setter; |
| 238 | p->m_Get = getter; |
| 239 | |
| 240 | // Push the Lua object and increase its ref count |
| 241 | lua_pushvalue(L, bufferindex); |
| 242 | p->m_BufferRef = dmScript::Ref(L, LUA_REGISTRYINDEX); |
| 243 | |
| 244 | luaL_getmetatable(L, SCRIPT_TYPE_NAME_BUFFERSTREAM); |
| 245 | lua_setmetatable(L, -2); |
| 246 | return 1; |
| 247 | } |
| 248 | |
| 249 | static BufferStream* CheckStreamNoError(lua_State* L, int index) |
| 250 | { |
no test coverage detected