From 6c8a9efb34f955d200b1ca17b66fb24bc1671245 Mon Sep 17 00:00:00 2001 From: DanielDual <96002450+DanielDual@users.noreply.github.com> Date: Wed, 27 Aug 2025 11:09:32 +0800 Subject: [PATCH] impl GetBGMTime and GetBGMTotalTime for Audio --- LuaSTG/LuaSTG/LuaBinding/LW_Audio.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/LuaSTG/LuaSTG/LuaBinding/LW_Audio.cpp b/LuaSTG/LuaSTG/LuaBinding/LW_Audio.cpp index a486c695..088eeeff 100644 --- a/LuaSTG/LuaSTG/LuaBinding/LW_Audio.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/LW_Audio.cpp @@ -382,6 +382,22 @@ void luastg::binding::Audio::Register(lua_State* L)noexcept p->SetLoop(loop); return 0; } + static int GetBGMTotalTime(lua_State* L) { + const char* s = luaL_checkstring(L, 1); + core::SmartReference p = LRES.FindMusic(s); + if (!p) + return luaL_error(L, "music '%s' not found.", s); + lua_pushnumber(L, p->GetAudioPlayer()->getTotalTime()); + return 1; + } + static int GetBGMTime(lua_State* L) { + const char* s = luaL_checkstring(L, 1); + core::SmartReference p = LRES.FindMusic(s); + if (!p) + return luaL_error(L, "music '%s' not found.", s); + lua_pushnumber(L, p->GetAudioPlayer()->getTime()); + return 1; + } }; luaL_Reg const lib[] = { @@ -412,6 +428,8 @@ void luastg::binding::Audio::Register(lua_State* L)noexcept { "SetBGMSpeed", &Wrapper::SetBGMSpeed }, { "GetBGMSpeed", &Wrapper::GetBGMSpeed }, { "SetBGMLoop", &Wrapper::SetBGMLoop }, + { "GetBGMTotalTime", &Wrapper::GetBGMTotalTime }, + { "GetBGMTime", &Wrapper::GetBGMTime }, { NULL, NULL }, };