| 850 | } |
| 851 | |
| 852 | static int Stream_index(lua_State* L) |
| 853 | { |
| 854 | DM_LUA_STACK_CHECK(L, 1); |
| 855 | BufferStream* stream = CheckStream(L, 1); |
| 856 | int index = luaL_checkinteger(L, 2) - 1; |
| 857 | if (index < 0 || index >= (int)(stream->m_Count * stream->m_TypeCount)) |
| 858 | { |
| 859 | if (stream->m_Count > 0) |
| 860 | { |
| 861 | return DM_LUA_ERROR("%s.%s only has valid indices between 1 and %d.", SCRIPT_LIB_NAME, SCRIPT_TYPE_NAME_BUFFERSTREAM, stream->m_Count * stream->m_TypeCount); |
| 862 | } |
| 863 | return DM_LUA_ERROR("%s.%s has no addressable indices, size is 0.", SCRIPT_LIB_NAME, SCRIPT_TYPE_NAME_BUFFERSTREAM); |
| 864 | } |
| 865 | |
| 866 | // convert contiguous index to stream space |
| 867 | uint32_t count = index / stream->m_TypeCount; |
| 868 | uint32_t component = index % stream->m_TypeCount; |
| 869 | lua_pushnumber(L, stream->m_Get(stream->m_Data, count * stream->m_Stride + component)); |
| 870 | return 1; |
| 871 | } |
| 872 | |
| 873 | static int Stream_newindex(lua_State* L) |
| 874 | { |
nothing calls this directly
no test coverage detected