gets data from a stream * * Get a copy of all the bytes from a specified stream as a Lua string. * * @name buffer.get_bytes * @param buffer [type:buffer] the source buffer * @param stream_name [type:hash] the name of the stream * @return data [type:string] the buffer data as a Lua string */
| 691 | * @return data [type:string] the buffer data as a Lua string |
| 692 | */ |
| 693 | static int GetBytes(lua_State* L) |
| 694 | { |
| 695 | DM_LUA_STACK_CHECK(L, 1); |
| 696 | dmBuffer::HBuffer hbuffer = dmScript::CheckBufferUnpack(L, 1); |
| 697 | |
| 698 | uint8_t* data; |
| 699 | uint32_t datasize; |
| 700 | dmBuffer::Result r = dmBuffer::GetBytes(hbuffer, (void**)&data, &datasize); |
| 701 | if( r != dmBuffer::RESULT_OK ) |
| 702 | { |
| 703 | return DM_LUA_ERROR("buffer.create: Failed getting buffer: %s", dmBuffer::GetResultString(r)); |
| 704 | } |
| 705 | |
| 706 | lua_pushlstring(L, (const char*)data, datasize); |
| 707 | return 1; |
| 708 | } |
| 709 | |
| 710 | ////////////////////////////////////////////////////////////////// |
| 711 | // BUFFER |