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

Function Stream_index

engine/gamesys/src/gamesys/scripts/script_buffer.cpp:852–871  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 3

CheckStreamFunction · 0.85
luaL_checkintegerFunction · 0.85
lua_pushnumberFunction · 0.85

Tested by

no test coverage detected