diff --git a/ag.cc b/ag.cc index dd28833..76889b7 100644 --- a/ag.cc +++ b/ag.cc @@ -327,6 +327,10 @@ namespace ag lua_setfield(L, -2, "loop"); lua_pushcfunction(L, sound::loopForever); lua_setfield(L, -2, "loopForever"); + lua_pushcfunction(L, sound::getVolume); + lua_setfield(L, -2, "getVolume"); + lua_pushcfunction(L, sound::setVolume); + lua_setfield(L, -2, "setVolume"); } static void createLuaAMotor(lua_State * L, int id) @@ -1701,5 +1705,36 @@ namespace ag } return 0; } + + int getVolume(lua_State * L) + { + int argc = lua_gettop(L); + if (argc == 1 && lua_istable(L, 1)) + { + refptr snd = getSound(L, 1); + if (!snd.isNull()) + { + float v = snd->getVolume(); + lua_pushnumber(L, v); + return 1; + } + } + return 0; + } + + int setVolume(lua_State * L) + { + int argc = lua_gettop(L); + if (argc == 2 && lua_istable(L, 1) && lua_isnumber(L, 2)) + { + refptr snd = getSound(L, 1); + if (!snd.isNull()) + { + float volume = lua_tonumber(L, 2); + snd->setVolume(volume); + } + } + return 0; + } } } diff --git a/ag.h b/ag.h index 36b073b..f59e52b 100644 --- a/ag.h +++ b/ag.h @@ -114,6 +114,8 @@ namespace ag int stop(lua_State * L); int loop(lua_State * L); int loopForever(lua_State * L); + int getVolume(lua_State * L); + int setVolume(lua_State * L); } }