mirror of
https://github.com/love2d/love.git
synced 2026-08-15 07:41:11 +02:00
pull request feedback addressed
newQueueableSource added isQueueable removed, getFreeBufferCount added queueData renamed to queue; added 3 argument variant with (data, offset, length) lightuserdata variant now requires offset (pointer, offset, length, samplerate, bitdepth, channels) setLooping now throws exception if called on queueable source --HG-- branch : minor
This commit is contained in:
@@ -330,34 +330,50 @@ int w_Source_getChannels(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Source_isQueueable(lua_State *L)
|
||||
int w_Source_getFreeBufferCount(lua_State *L)
|
||||
{
|
||||
Source *t = luax_checksource(L, 1);
|
||||
luax_pushboolean(L, t->isQueueable());
|
||||
lua_pushinteger(L, t->getFreeBufferCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Source_queueData(lua_State *L)
|
||||
int w_Source_queue(lua_State *L)
|
||||
{
|
||||
Source *t = luax_checksource(L, 1);
|
||||
bool success;
|
||||
|
||||
luax_catchexcept(L, [&]() {
|
||||
if (luax_istype(L, 2, SOUND_SOUND_DATA_ID))
|
||||
{
|
||||
love::sound::SoundData *s = luax_totype<love::sound::SoundData>(L, 2, SOUND_SOUND_DATA_ID);
|
||||
success = t->queueData(s->getData(), lua_isnumber(L, 3) ? (int)lua_tonumber(L, 3) : s->getSize(), s->getSampleRate(), s->getBitDepth(), s->getChannels());
|
||||
}
|
||||
else if (lua_islightuserdata(L, 2))
|
||||
{
|
||||
if (lua_isnumber(L, 4) && lua_isnumber(L, 5) && lua_isnumber(L, 6))
|
||||
success = t->queueData(lua_touserdata(L, 2), (int)lua_tonumber(L, 3), (int)lua_tonumber(L, 4), (int)lua_tonumber(L, 5), (int)lua_tonumber(L, 6));
|
||||
else
|
||||
return luaL_error(L, "No format specified.");
|
||||
}
|
||||
else
|
||||
return luaL_error(L, "Invalid data type.");
|
||||
});
|
||||
if (luax_istype(L, 2, SOUND_SOUND_DATA_ID))
|
||||
{
|
||||
love::sound::SoundData *s = luax_totype<love::sound::SoundData>(L, 2, SOUND_SOUND_DATA_ID);
|
||||
|
||||
int length = lua_isnumber(L, 4) ? lua_tonumber(L, 4) : ( lua_isnumber(L, 3) ? lua_tonumber(L, 3) : s->getSize() );
|
||||
int offset = lua_isnumber(L, 4) ? lua_tonumber(L, 3) : 0;
|
||||
|
||||
if (length > s->getSize() - offset || offset < 0 || length < 0)
|
||||
return luaL_error(L, "Data region out of bounds.");
|
||||
|
||||
luax_catchexcept(L, [&]() {
|
||||
success = t->queue((void*)((uintptr_t)s->getData() + (uintptr_t)offset),
|
||||
length, s->getSampleRate(), s->getBitDepth(), s->getChannels());
|
||||
});
|
||||
}
|
||||
else if (lua_islightuserdata(L, 2))
|
||||
{
|
||||
if (!(lua_isnumber(L, 3) && lua_isnumber(L, 4)))
|
||||
return luaL_error(L, "No region specified.");
|
||||
if (!(lua_isnumber(L, 5) && lua_isnumber(L, 6) && lua_isnumber(L, 7)))
|
||||
return luaL_error(L, "No format specified.");
|
||||
if (lua_tonumber(L, 3) < 0 || lua_tonumber(L, 4) < 0)
|
||||
return luaL_error(L, "Data region out of bounds.");
|
||||
|
||||
luax_catchexcept(L, [&]() {
|
||||
success = t->queue((void*)((uintptr_t)lua_touserdata(L, 2) + (uintptr_t)lua_tonumber(L, 3)),
|
||||
lua_tonumber(L, 4), (int)lua_tonumber(L, 5), (int)lua_tonumber(L, 6), (int)lua_tonumber(L, 7));
|
||||
});
|
||||
}
|
||||
else
|
||||
return luax_typerror(L, 1, "Sound Data or lightuserdata");
|
||||
|
||||
luax_pushboolean(L, success);
|
||||
return 1;
|
||||
}
|
||||
@@ -415,8 +431,8 @@ static const luaL_Reg w_Source_functions[] =
|
||||
|
||||
{ "getChannels", w_Source_getChannels },
|
||||
|
||||
{ "isQueueable", w_Source_isQueueable },
|
||||
{ "queueData", w_Source_queueData },
|
||||
{ "getFreeBufferCount", w_Source_getFreeBufferCount },
|
||||
{ "queue", w_Source_queue },
|
||||
|
||||
{ "getType", w_Source_getType },
|
||||
|
||||
|
||||
Reference in New Issue
Block a user