Add SoundData:slice

SoundData:slice(start, length = -1)

When length = -1, it will slice until the end.
This commit is contained in:
Miku AuahDark
2020-09-22 13:09:03 +08:00
parent e71441d68b
commit 04b20624b2
3 changed files with 33 additions and 4 deletions
+13
View File
@@ -134,6 +134,18 @@ int w_SoundData_copyFrom(lua_State *L)
return 0;
}
int w_SoundData_slice(lua_State *L)
{
SoundData *t = luax_checksounddata(L, 1), *c = nullptr;
int start = (int) luaL_checkinteger(L, 2);
int length = (int) luaL_optinteger(L, 3, -1);
luax_catchexcept(L, [&](){ c = t->slice(start, length); });
luax_pushtype(L, c);
c->release();
return 1;
}
static const luaL_Reg w_SoundData_functions[] =
{
{ "clone", w_SoundData_clone },
@@ -145,6 +157,7 @@ static const luaL_Reg w_SoundData_functions[] =
{ "setSample", w_SoundData_setSample },
{ "getSample", w_SoundData_getSample },
{ "copyFrom", w_SoundData_copyFrom },
{ "slice", w_SoundData_slice },
{ 0, 0 }
};