From 9ee11409c549bfe137c14baad8521be7e97c90a9 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Thu, 27 Jul 2017 17:40:56 +0200 Subject: [PATCH] Add vararg versions of love.audio.play/pause/stop (fixes #1295) The table versions existed already, I guess I forgot about varargs --HG-- branch : minor --- src/modules/audio/wrap_Audio.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/modules/audio/wrap_Audio.cpp b/src/modules/audio/wrap_Audio.cpp index d3c985b50..2503b9f67 100644 --- a/src/modules/audio/wrap_Audio.cpp +++ b/src/modules/audio/wrap_Audio.cpp @@ -115,16 +115,34 @@ static std::vector readSourceList(lua_State *L, int n) return sources; } +static std::vector readSourceVararg(lua_State *L, int i) +{ + const int top = lua_gettop(L); + + if (i < 0) + i += top + 1; + + int items = top - i + 1; + std::vector sources(items); + + for (int pos = 0; i <= top; i++, pos++) + sources[pos] = luax_checksource(L, i); + + return sources; +} + int w_play(lua_State *L) { if (lua_istable(L, 1)) - { luax_pushboolean(L, instance()->play(readSourceList(L, 1))); - return 1; + else if (lua_gettop(L) > 1) + luax_pushboolean(L, instance()->play(readSourceVararg(L, 1))); + else + { + Source *s = luax_checksource(L, 1); + luax_pushboolean(L, instance()->play(s)); } - Source *s = luax_checksource(L, 1); - luax_pushboolean(L, instance()->play(s)); return 1; } @@ -134,6 +152,8 @@ int w_stop(lua_State *L) instance()->stop(); else if (lua_istable(L, 1)) instance()->stop(readSourceList(L, 1)); + else if (lua_gettop(L) > 1) + instance()->stop(readSourceVararg(L, 1)); else { Source *s = luax_checksource(L, 1); @@ -158,6 +178,8 @@ int w_pause(lua_State *L) } else if (lua_istable(L, 1)) instance()->pause(readSourceList(L, 1)); + else if (lua_gettop(L) > 1) + instance()->pause(readSourceVararg(L, 1)); else { Source *s = luax_checksource(L, 1);