From c83809e7ae6cb5bfeae438792f5135c783bdd8ac Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sun, 23 Apr 2017 05:36:25 -0400 Subject: [PATCH] Return nil instead of #wesnoth.playlist+1 when the current track is not on the playlist --- src/scripting/lua_audio.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/scripting/lua_audio.cpp b/src/scripting/lua_audio.cpp index 52160e5c9bfc..5cb47b52f6de 100644 --- a/src/scripting/lua_audio.cpp +++ b/src/scripting/lua_audio.cpp @@ -63,7 +63,15 @@ static int impl_music_get(lua_State* L) { push_track(L, sound::get_current_track()); return 1; } - return_int_attrib("current_i", sound::get_current_track() + 1); + if(strcmp(m, "current_i") == 0) { + size_t i = sound::get_current_track(); + if(i == sound::get_num_tracks()) { + lua_pushnil(L); + } else { + lua_pushinteger(L, i + 1); + } + return 1; + } // This calculation reverses the one used in [volume] to get back the relative volume level. // (Which is the same calculation that's duplicated in impl_music_set.) return_float_attrib("volume", sound::get_music_volume() * 100.0f / preferences::music_volume());