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

Function CopyStream

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

copies data from one stream to another * * Copy a specified amount of data from one stream to another. * * [icon:attention] The value type and size must match between source and destination streams. * The source and destination streams can be the same. * * @name buffer.copy_stream * @param dst [type:bufferstream] the destination stream * @param dstoffse

Source from the content-addressed store, hash-verified

519 * ```
520 */
521 static int CopyStream(lua_State* L)
522 {
523 DM_LUA_STACK_CHECK(L, 0);
524 BufferStream* dststream = CheckStream(L, 1);
525 int dstoffset = luaL_checkint(L, 2);
526
527 BufferStream* srcstream = 0;
528 if( IsStream(L, 3) )
529 {
530 srcstream = CheckStream(L, 3);
531 }
532 else
533 {
534 return luaL_typerror(L, 3, SCRIPT_TYPE_NAME_BUFFERSTREAM);
535 }
536
537 int srcoffset = luaL_checkint(L, 4);
538 int count = luaL_checkint(L, 5);
539
540 if(srcstream)
541 {
542 if( dststream->m_Type != srcstream->m_Type )
543 {
544 return DM_LUA_ERROR("The types of the streams differ. Expected 'buffer.%s', got 'buffer.%s'",
545 dmBuffer::GetValueTypeString(dststream->m_Type), dmBuffer::GetValueTypeString(srcstream->m_Type) );
546 }
547 if( dststream->m_TypeCount != srcstream->m_TypeCount )
548 {
549 return DM_LUA_ERROR("The type count of the streams differ. Expected %u 'buffer.%s', got %u 'buffer.%s'",
550 dststream->m_TypeCount, dmBuffer::GetValueTypeString(dststream->m_Type), srcstream->m_TypeCount, dmBuffer::GetValueTypeString(srcstream->m_Type) );
551 }
552
553 if( (uint32_t)(dstoffset + count) > dststream->m_Count * dststream->m_TypeCount )
554 {
555 return DM_LUA_ERROR("Trying to write too many values: Stream length: %d, Offset: %d, Values to copy: %d", dststream->m_Count, dstoffset, count);
556 }
557 if( (uint32_t)(srcoffset + count) > srcstream->m_Count * srcstream->m_TypeCount )
558 {
559 return DM_LUA_ERROR("Trying to read too many values: Stream length: %d, Offset: %d, Values to copy: %d", srcstream->m_Count, srcoffset, count);
560 }
561
562 if (!CopyStreamInternal(dststream, dstoffset, srcstream, srcoffset, count))
563 {
564 return DM_LUA_ERROR("Unknown stream value type: %d", dststream->m_Type);
565 }
566 }
567 return 0;
568 }
569
570 /*# copies one buffer to another
571 *

Callers

nothing calls this directly

Calls 5

CheckStreamFunction · 0.85
IsStreamFunction · 0.85
GetValueTypeStringFunction · 0.85
CopyStreamInternalFunction · 0.85
luaL_typerrorFunction · 0.50

Tested by

no test coverage detected